Boriel Basic Forum
non-paged supervisor code calling paged application code - Printable Version

+- Boriel Basic Forum (https://forum.boriel.com)
+-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://forum.boriel.com/forumdisplay.php?fid=16)
+---- Thread: non-paged supervisor code calling paged application code (/showthread.php?tid=2651)



non-paged supervisor code calling paged application code - sdo303 - 2026-02-15

Firstly, a proper thankyou to Boriel for the compiler.   And secondly, also a proper thankyou to Duefectu for the beginner's guide book (I bought a hard copy), which I have read cover to cover (but I did skip the sound/audio sections Smile).  And I bought a hard copy of Simon G's NextTech book too, again I have read it cover to cover (but skipped the sound/audio parts).

Using Boriel ZXBasic and as little Z80 machine code as I can get away with (until I need to performance tune)... my project is that I am trying to write a quasi "character cell" based application, like being on an old VT100, whereby the application uses all 64KB of the Z80 for itself, and thus no ZX Spectrum ROM, and which internally leverages a poor man's virtual memory framework, whereby I have a supervisor layer of non-paged code running in MMU0/1, which boots from $0000 and jumps over IM1 at $0038 to begin my main code properly at say $0050 where the application begins properly... and so I have my core non-paged system variables mapped in MMU2 and then I have my paged code to run from MMU3 - and then various different aspects of paged application data paging in and out MMU4/5/6, with finally MMU7 again being static non-paged to host the 5KB of screen tile map for an 80x32 screen, with the final 3KB of MMU7 being available for the stack pointer from $FFFE downwards.
phew...
I know my code will never work first time, I get that... but I feel fairly sure that I have the basic (excuse the pun) initial structure of what I want to achieve, with all of my system variables (so far identified) defined at static addresses in MMU2, and my main supervisor MMU paging and also my screen updating routines and keyboard reading routines written (to be permanently resident in MMU0/1) and the first of my paged blocks of code to run from MMU3, and I have gotten the source code clean enough pass through zxbc without the compiler spitting any hard errors... (just lots and lots of warnings)... but I've now hit a roadblock...

I get how I can have many separate pages of 8KB deposited across the ZX Next vast 200+ pages of 8KB across 1.75 MB of RAM, and I get how I can have my code paged in at MMU3 for my application to execute from $6000, and I can get my non-paged supervisor layer code to make calls such as       uw_dummy = USR $6000     to call my paged code in MMU3, and thus wait for a return... but what I don't understand is how I can have many different paged code blocks where each is aware of *ALL* of the available core supervisor routines and their parameter structures and thus able to makes calls back in to the supervisor to run any of the many core system routines...

i.e. how can I make zxbc firstly compile the application core without dropping routines that zxbc thinks are unused, and yet also somehow get the compilations of many different "paged" application code to be aware of the core supervisor routines and their parameters and any return value data types (of functions).

e.g. I get this from my compilation of my "core.bas":
core.bas:115: warning: [W170] Function 's_crash' is never called and has been ignored
core.bas:154: warning: [W170] Function 's_fc_ram_copy' is never called and has been ignored
core.bas:165: warning: [W170] Function 's_clear_screen' is never called and has been ignored
core.bas:126: warning: [W170] Function 's_print_char_at' is never called and has been ignored
core.bas:143: warning: [W170] Function 's_print_string_at' is never called and has been ignored
core.bas:217: warning: [W170] Function 's_display_monitor' is never called and has been ignored
core.bas:283: warning: [W170] Function 'fub_key_get_minutes' is never called and has been ignored

...and I get this for my first stage of my application:
stage-include.bas:37: warning: [W170] Function 's_next_reg' is never called and has been ignored
stage-include.bas:38: warning: [W170] Function 's_return_to_zxos' is never called and has been ignored
stage-include.bas:39: warning: [W170] Function 's_crash' is never called and has been ignored
stage-include.bas:40: warning: [W170] Function 's_fc_ram_copy' is never called and has been ignored
stage-include.bas:42: warning: [W170] Function 's_clear_screen' is never called and has been ignored
stage-include.bas:43: warning: [W170] Function 's_print_char_at' is never called and has been ignored
stage-include.bas:44: warning: [W170] Function 's_print_string_at' is never called and has been ignored
stage-include.bas:45: warning: [W170] Function 's_display_monitor' is never called and has been ignored
stage-include.bas:47: warning: [W170] Function 'fub_key_get_minutes' is never called and has been ignored
stage-include.bas:48: warning: [W170] Function 's_key_wait_for_vblank' is never called and has been ignored
stage-include.bas:49: warning: [W170] Function 's_get_key' is never called and has been ignored
...
stage-init.bas:8: warning: [W170] Function 's_stage_init' is never called and has been ignored
stage-init.bas:20: warning: [W170] Function 's_init_keyboard_table_ZX_keys' is never called and has been ignored
stage-init.bas:21: warning: [W170] Function 's_init_keyboard_table_ZX_symkeys' is never called and has been ignored
stage-init.bas:18: warning: [W170] Function 's_init_load_palette' is never called and has been ignored
stage-init.bas:186: warning: [W170] Function 's_init_load_palette_entry' is never called and has been ignored
stage-init.bas:223: warning: [W170] Function 's_init_clear_screen' is never called and has been ignored
stage-init.bas:26: warning: [W170] Function 's_init_title_screen' is never called and has been ignored

...where stage-include.bas was my attempt to make each "stage" aware of a jump-table of locations of core routines:
Asm
    ; fixed jump table addresses for the linker
    _s_main                          equ $0050
    _s_next_reg                      equ $0053
    _s_return_to_zxos                equ $0056
    _s_crash                         equ $0059
    _s_fc_ram_copy                   equ $005C
    _s_clear_screen                  equ $005F
    _s_print_char_at                 equ $0062
    _s_print_string_at               equ $0065
    _s_display_monitor               equ $0068
    _fub_key_get_minutes             equ $006B
    _s_key_wait_for_vblank           equ $006E
    _s_get_key                       equ $0071
End Asm


' implementation blocks to stop "not implemented" errors
' these contain no code; the equate above handles the address
Sub s_main(): End Sub
Sub s_next_reg(reg As UByte, value As UByte): End Sub
Sub s_return_to_zxos(): End Sub
Sub s_crash(error_code As UByte, error_text As String): End Sub
Sub Fastcall s_fc_ram_copy(src_address As UInteger, dest_address As UInteger, byte_count As UInteger): End Sub
Sub s_clear_screen(): End Sub
Sub s_print_char_at(x As UByte, y As UByte, char As UByte, colour As UByte): End Sub
Sub s_print_string_at(x As UByte, y As UByte, text As String, colour As UByte): End Sub
Sub s_display_monitor(): End Sub
Function fub_key_get_minutes() As UByte: return 0: End Function
Sub s_key_wait_for_vblank(): End Sub
Sub s_get_key(): End Sub



But clearly there is something I'm not getting, and I've reached the limits of capability of AI helper tools.

I had rationalised to myself that my build script should only call to zxbc to produce "-f asm" ASM files... as I expect to have to then somehow "link" the static core ASM and the many paged stage ASM together at some point... and I also seem to have rationalised that I may perhaps need to use     sjasmplus     to assemble my ".nex" package.

Does the above sound achievable?  Or am I asking too much of the "Next" as a platform?  i.e. is the "Next" only any good for paging graphics data, and no good for paging application code?


RE: non-paged supervisor code calling paged application code - sdo303 - 2026-02-15

ok - so I have managed to get the compilation (to ASM) of my "core.bas" supervisor to no longer drop the routines (as uncalled) by getting my s_main() routine to call this dummy "do nothing" routine:

Sub s_super_keeper()
    Dim p, q, swap As UInteger
    p = @s_next_reg
    p = @s_return_to_zxos
    p = @s_crash
    p = @s_fc_ram_copy
    p = @s_clear_screen
    p = @s_print_char_at
    p = @s_print_string_at
    p = @s_display_monitor
    p = @fub_sys_get_minutes
    p = @s_wait_for_vblank
    p = @s_get_key
    swap = p
    p = q
    q = swap
End Sub

...with a final variable swap to stop the compiler from noticing that 'p' does nothing genuinely useful...

...now back to trying to determine how to make calls back to routines in the supervisor.... hmmm.