Comments (6)
the sub-word substitution is close, with the problem being the createFarLabel macro pushing the label into the code section and making it difficult to pick out from the actual code. (the issue of the JP test1_far part being fixed by including an extra label creation in the createFarLabel macro (without the _far suffix))
that being said the real device example you gave is basically perfect anyway, so i'll be using that.
(the static rom part is actually rom page 0, and can be (uselessly) paged into the banked rom part, but i can figure that out on my own now.)
also the docs feel... lacking? when it comes to information on real device stuff, or rather... it all spread out?
like the docs talk about the $$label stuff, but not in the label section or the MMU section, only in the "expression" section.
plus they don't really give a full example of the real device stuff, again maybe it's spread out and not easy to completely find?
so it was only after reading the full example you gave that i was able to find/understand some of the information about the device/mmu stuff.
and the substituting of sub-words isn't talked about at all? i mean there's the counter example but nothing else, right?
from sjasmplus.
I think I know how to work this around, will try to answer tomorrow (too late now here)
... but I'm curious, any chance for you to use one of the virtual DEVICE
stuff? Seems to me like ZXSPECTRUMxxxx would maybe with with the 16ki pages if you have banks at 0x4000..0x7FFF
That way you can use built-in page operator $$label
and also equ
allows to define page label equ address,page
.
I generally find using the virtual DEVICE easier, as I can build full project in virtual memory assigning correct address/pages to all code by using MMU
(eventually DISP
if needed), the page operators (to avoid magic numbers in code) and then save everything in one go to the final file.
from sjasmplus.
i don't really understand the DEVICE stuff, are there memory maps, or are the banks anywhere in address space?
the hardware i'm working with has 16kB static of ROM @0x0000, then 8 16kB pages of banked rom @0x4000, then 32kB of ram @0x8000.
as stated i don't understand the DEVICE stuff so i can't tell is that aligns with any of the predefined thing or not.
will have to look into it in the morning.
from sjasmplus.
so that's like 11 16ki blocks (1+8+1+1). You can "bend" ZXSPECTRUM256
device for that, creating your own notation where pages 0..7 are the banked roms, then for example 8 is static rom and 9 and 10 are ram.
I tried to prepare full example, also showing some usage of the $$label
page operator and MMU
features.
; assigning sjasmplus virtual device memory pages to map your system like this:
; 0..7 - banked ROM 0..7
; 8 - static ROM
; 9, 10 - 32kiB of RAM
BANKED_ROM_PAGES EQU 8 ; count of banked ROM pages
STATIC_ROM_PAGE EQU BANKED_ROM_PAGES
RAM_PAGE_0 EQU STATIC_ROM_PAGE+1
RAM_PAGE_1 EQU RAM_PAGE_0+1
MACRO createCall label?
CALL callTableFunction
DW label? ; address
DB $$label? ; page number
ENDM
DEVICE ZXSPECTRUM256 ; this device has 16x 16kiB pages, so the designed custom layout fits
BLOCK 0x10000, 0x00 ; clear the ZX Spectrum specific pre-init of memory (system variables/VRAM/etc)
; map the static ROM and RAM pages
MMU 0x0000, STATIC_ROM_PAGE ; map "static ROM" page 8 to 0x0000..0x3FFF
MMU 0x8000 0xC000, RAM_PAGE_0 ; map "RAM" pages 8+9 to 0x8000..0xFFFF
;; preparing banked ROM code (for each page)
; ROM 0
MMU 0x4000 e, 0, 0x4000 ; map "banked ROM 0" page 0 to 0x4000..0x7FFF, do ORG 0x4000, error when going beyond
test1
jp test1
; ROM 1
MMU 0x4000 e, 1, 0x4000 ; map "banked ROM 1" page 1 to 0x4000..0x7FFF
test2
jp test2
BLOCK 0x4000, 0xAA ; raises error about crossing the page boundary (showcasing "e" option of MMU)
; you can also use EQU to define address+page, like test3 pointing to ROM 5 at 0x4321
test3 EQU 0x4321, 5
; create static ROM code (sjasmplus page 8)
ORG 0x0000
callTableFunction:
; code that switches ROM bank and calls/jumps to actual function
RET
showcaseDataUsage:
ld hl,data1
ld a,$$data1 ; page 9 of sjasmplus for the RAM (probably irrelevant on your system, but on banked RAM... you get the idea)
ld a,$$data3 ; page 10 of sjasmplus for data3 label
callTable:
createCall test1
createCall test2
createCall test3
; data in RAM
ORG 0x8000
data1:
DB "some RAM data maybe if you want"
data2:
DS 123 ; or just reserving space for uninitialized data
ORG 0xC000
data3
DB "tag second 16ki page of RAM in RAM.bin"
; dumping the device device memory into files
SAVEDEV "staticROM.bin", STATIC_ROM_PAGE, 0x0000, 0x4000
SAVEDEV "bankedROM.bin", 0, 0x0000, BANKED_ROM_PAGES*0x4000
SAVEDEV "RAM.bin", RAM_PAGE_0, 0x0000, 0x8000 ; save both pages 9+10 in one go
; the consecutive pages used by banked ROM and RAM enables SAVEDEV to use lengths like 8*0x4000
; dumping the data from the linear 256kiB virtual device memory space
Let me know if this works for you, or if you can't figure out how something works, but as far as I can tell, this should fit your use case almost perfectly?
edit: the point of stuff like DEVICE + MMU + $$
operator is to avoid hard-coded magic numbers and having mostly assembler figuring out what is where, except initial memory layout setup, to avoid typo-like bugs when assigning pages manually.
from sjasmplus.
back to your original question ... one possible solution is to use sub-word substitution, when you have DEFINE/macro argument name with underscores, the substitution engine is substituting also sub-words, so this works:
MACRO createFarLabel label?
label?_far
@.bank equ bank
ENDM
MACRO createFarCall label?
CALL callTableFunction
DW label?_far
DB label?_far.bank ; throws error saying that "label.bank" cannot be found, need to be able to say that "label" is an arg, not a label:
ENDM
callTableFunction:
; code that switches ROM bank and calls/jumps to actual function
RET
callTable:
createFarCall test1
createFarCall test2
bank DEFL 0
PHASE 0x4000 ; changable ROM bank starts at 0x4000 and ends at 0x7FFF
createFarLabel test1
jp test1_far
UNPHASE
bank = bank + 1
PHASE 0x4000 ; changable ROM bank starts at 0x4000 and ends at 0x7FFF
createFarLabel test2
jp test2_far
UNPHASE
So this does create test1_far
and test1_far.bank
, the underscore "_far" being used to get sub-word substitution of macro argument "label?" (I prefer to append macro arguments with ?
just to make them more stand-out in source and also make less likely sub-word substitution by accident... as you can see from this example, it's quite easy to get unexpected substitutions if you use short generic DEFINE/macro argument names, and you also like to use longer names with underscores reusing those short words, it was so annoying I added lately --syntax=s
for people who don't want this feature to just disable it off completely.
from sjasmplus.
static ROM: yup. But then assembling the code at 0x0000 is also visible at 0x4000 if you map the same page 0 into both "slots", and also other way, assembling at 0x4000 overwrites also bytes at 0x0000, so have some plan how to divide the page into independent areas for 0x0000/0x4000 mapping to not overlap them.
docs feedback: thank you, the device is somewhat hairy, I have difficult time to fully see it with fresh eyes, as I went very early into sjasmplus source fixing its bugs I did spot while quickly reading through it. So I did learn a lot from its source.
So any feedback like this is welcome and very valuable.
(also if you git-clone full repo or check the github web interface, there's lot of tests covering functionality, so when docs are not clear about particular directive, you may try to look for tests covering it, sometimes they help with extra context about usage, unless the test is too synthetic).
sub-word substitution was my first issue opened here ... #37 ... instead of getting answers, I ended up refactoring the implementation... :) ... so this needs fixing, I agree.
sub-word substitution example: well, you can also put the test1_far
outside, it doesn't have to be constructed from within macro by substitution, as long as the label is same. But if you manage to jump on the DEVICE
bandwagon, you will have more powerful features available, like the $$label
operator, etc.
Closing the issue as this is departing from original topic (and turning into issues which I think already are open like the docs), but feel free to ask for any remaining details here, or even reopen if needed, have fun. :)
from sjasmplus.
Related Issues (20)
- Typo on warning
- [1.20.1][ubuntu 22.04][mingw-w64] Can't compile windows exe without modifying Makefile // Recommendation in Makefile is also not full
- Allow multiple labels as arguments of IFUSED HOT 3
- Multiple ORG directives silently ignored? HOT 2
- Interest in adding a new Z80 device ? VZ200/Laser210 HOT 3
- Incorrect compilation of DC with one symbol in single quotes HOT 5
- Not everything works after return from snapshot to Basic HOT 2
- Arrow keys and ESC don't work after invoking sjasmplus HOT 5
- Tests may fail due to locale settings
- duplicate lables HOT 1
- get include length size HOT 2
- bplist: MAME support HOT 1
- union HOT 1
- lua block parsing inside macro is not aware of being inside lua block, applying sjasmplus parsing rules (colons!) HOT 1
- Concern about instructions like add a,b HOT 4
- Missing FAKE INSTRUCTIONS like "ex bc, hl" and other combinations that exploit "ex (sp), rr" HOT 4
- INCBIN command assumes current OS path based on the .asm file where it resides. Does this have to be the case? HOT 4
- DEVICE for ZX Spectrum +3? HOT 3
- savesna PC counter seem to get lost between sjasmplus 1.14.5 and newer versions when using NexCreator HOT 3
- ZX80/ZX81 virtual device for sld output HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sjasmplus.