ZXMoria v0.9 beta: Umoria 5.7.15, The Dungeons of Moria, ported to the ZX Spectrum Next in Boriel BASIC, free under GPL v3, with a ready-to-run .nex. Only tested in ZEsarUX so far, so reports from real Nexts are very welcome: https://github.com/sdo101/zxmoria
just posted/shared, a small, working example of 8KB MMU paging on the ZX Spectrum Next in Boriel BASIC (all eight slots, paged code and data, shims, one shared heap, save/load), free under MIT, with a ready-to-run .nex: https://github.com/sdo101/zxpaging
After a little while away from Boriel and am returning to it. I have been looking at GuSprites, but the documentation is limited. Is there any tutorials or documentation that would help a beginner?
------------------------------------------------------------------- Español
Estoy creando un curso de Boriel Basic en vídeo.
Lo tenéis disponible en: https://youtu.be/8AkYffB--bk?si=eL9yz9oPLpi6y0wE
I'd like to use strings and arrays in my paged code, but I seem to have reached a blockage whereby, even though my paged-code looks like:
Code:
#PRAGMA push(case_insensitive)
#PRAGMA case_insensitive = True
#define STANDALONE ' remove ROM initialization and SysVars...
Asm
org $6000
di
End Asm
s_stage_init()
Asm
ret
End Asm
#include "constants.bas"
#include "globals.bas"
#include "stage-include.bas"
Sub s_init_keyboard_table_ZX_keys()
' effect: populates the lookup table for the 40-key spectrum matrix
' row 0: port $FEFE
gub_zxkeys(0) = 0 ' caps shift
'...
gub_zxkeys(55) = 127 ' delete (standard)
End Sub
Sub s_init_keyboard_table_ZX_symkeys()
' row 0: z, x, c, v
gub_zxsymkeys(1) = 58 ' :
'...
gub_zxsymkeys(55) = 127 ' delete (standard)
End Sub
Sub s_init_title_screen()
' footer prompt
s_print_string_at( 28, 21, "Press any key to begin..." , UB_BRIGHT_YELLOW )
' wait for player input
s_get_key()
' check if the one-hour timeout occurred
If guw_key_code = 0 Then gub_core_end = true
End Sub
Sub s_stage_init()
s_init_keyboard_table_ZX_keys()
s_init_keyboard_table_ZX_symkeys()
s_init_title_screen()
End Sub
then I still seem to end up with some kind of header code that makes a call to $46A4...
Code:
>6001 CALL 46A4 PC 6001
6004 NOP SP FFFA
6005 NOP AF FFFF'3C40
6006 NOP SZ5H3PNC
6007 NOP HL 0001'3C44
6008 NOP DE 0000'FFFF
6009 NOP BC 0000'5393
600A LD BC, 6013 IX FFF1
600D EX AF, AF' IY EFF3
600E LD B, A IR 001B
600F NOP IM1 IFF--
6010 NOP (HL) F3 00
6011 NOP (DE) 00 F3
(BC) 00 F3
(SP) 0C3C 010B 0000 F300 C300 0
which I think must be some kind of heap management setup...
...so please may I ask...
Is there a compiler switch or directive whereby I can get the heap management code tacked on just after my code ends, so that I can have private heap management per 8KB segment of paged code ?
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 ). 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 Subs_main(): EndSub Subs_next_reg(reg As UByte, value As UByte): EndSub Subs_return_to_zxos(): EndSub Subs_crash(error_code As UByte, error_text As String): EndSub SubFastcall s_fc_ram_copy(src_address As UInteger, dest_address As UInteger, byte_count As UInteger): EndSub Subs_clear_screen(): EndSub Subs_print_char_at(x As UByte, y As UByte, char As UByte, colour As UByte): EndSub Subs_print_string_at(x As UByte, y As UByte, text As String, colour As UByte): EndSub Subs_display_monitor(): EndSub Functionfub_key_get_minutes() As UByte: return 0: EndFunction Subs_key_wait_for_vblank(): EndSub Subs_get_key(): EndSub
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?
He has created a fast plot routine, (hellaplot), so I thought I'd try and convert it to a Boriel Basic (BB) subroutine, just for fun and learning - and as it was a single routine.
I had to do a little bit of reading, but also had to ask for help from the BB telegram community, as to begin with the code was crashing the emulator. Turns out it was a simple fix when you know how - FASTCALL was needed when passing parameters for ASM to use from a SUB routine.
Andy's code needs the x/y locations in DE, so I had to do a little bit to get them set up like this - I assume there might be some more efficiency if different registers were used as BB passes from the subroutine call, the first parameter into A, and the second parameter is the second item on the stack (the first being the return address).
When I started, xPos was the first parameter, and yPos the second (as I like x,y), but this meant to get them into DE, took another load (POP DE, LD E with D, LD D with A, compared to POP DE, LD E with A)
So some "non exact" timings - plot included as the library in BB takes about 15 seconds to fill up the screen with "points". Andy's one takes 5 seconds to do the same.
As far as Andy's code goes, I understand the comments, but not exactly how it works :-)
Anyway, code below :
SUB FASTCALL HellaPrint(yPos as UBYTE, xPos as UBYTE)
' HellaPrint prints an x,y pixel
' 0,0 is top left
' Original code by Andy Lansby
' https://zxspectrumcoding.wordpress.com/
' yPos is first, as it save a LD instruction when putting xPos and yPos into DE
ASM
JP START ; Put this in as it's like this on the Wiki ASM desciption - can it be avoided?
X_PositionBits: defb 128,64,32,16,8,4,2,1
; Might there be a quicker way to do the above, so it's not needed every time the program is run? or does it not work like this and is created once at compile time?
START: ; plot d = x-axis, e = y-axis
; A contains the yPos, xPos is on stack.
POP HL ; Pops the return address into HL
POP DE ; xPos is on the stack, and it needs to be in D
LD E, A ; A has our first paramter (yPos), load it into E. D should be Xpos, E should be yPos
PUSH HL ; Puts the return address back onto stack ...
; 166 T states per pixel
XOR A ; reset A to 0 and flags to default
LD A,E ; load Y plot point
RRA ; rotate Right --- divide in half
SCF ; turn on Carry flag-
RRA ; rotate right with the carry flag
OR A ; set flag S on - C flag off
RRA ; rotate Right --- divide in half
LD L,A ; temp store in L
XOR E ; XOR the Y value
AND %11111000 ; mask out bottom 3 bits
XOR E ; XOR the Y value
LD H,A ; store High byte
LD A,D ; load X plot point
XOR L ; XOR the temp value
AND %00000111 ; mask out unwanted bits
XOR D ; XOR the X value
RRCA ; divide by 2
RRCA ; divide by 4
RRCA ; divide by 8
LD L,A ; store Low byte
; now we have the full address
; now use LUT to find which bit to set
LD A,D ; load X plot point
AND %00000111 ; mask out unwanted bits
; use a LUT to quickly find the bit position for the X position
LD DE,X_PositionBits ; load LUT address into DE
ADD A,E ; Add A to E to get offset into table
LD E,A ; E now points to the LUT entry
LD A,(DE) ; load answer into A
; output to screen
OR (HL) ; or with contents of address HL
LD (HL),A ; load address HL with Answer from A
END ASM
END SUB
HOF.zxbas - Hall of fame procedures
main.zxbas - a demo
Attached is a little "library" for a Hall of Fame / High Score table.
To use it - you need to create two Arrays (at least 2 ...)
Array 1 = UInteger, for scores
Array 2 = String, for names
Probably best to keep to 10 entries, but could be more. You can have more than 1 HOF, so could have Array2, Arry3 etc etc for say Easy Score, Medium Scores, Hard Scores. As it passes the Arrays by reference, no other variables are needed.
Completely and utterly free to use, adapt, change, republish how ever you want.
Arraybase is 0
SUB HOF_IntialiseHOF(BYREF HOF_Scores() AS UINTEGER, BYREF HOF_Names() AS STRING, HOF_IntialTopScore as UINTEGER,HOF_InitialName AS STRING)
Use this to initialise the two HOF arrays - with a "highest score, working down to a low score and gives each entry "InitialName".
FUNCTION HOF_HighScore_CheckEntry (HOF_Scores() AS UINTEGER, NewHighScore as UINTEGER) AS BYTE
Returns 1 if the High Score can g into the Arrays.
SUB HOF_HighScore_NewEntry (BYREF HOF_Scores() AS UINTEGER, BYREF HOF_Names() AS STRING, NewHighScore as UINTEGER, NewHighScoreName AS STRING)
Puts the new entries (name & score) into the HOF array.
SUB HOF_Print(BYREF HOF_Scores() AS UINTEGER, BYREF HOF_Names() AS STRING, YPOS as INTEGER, XPOS as INTEGER)
A simple print location, witch prints the Score and Names. Will carry on printing if you have many entries ...
SUB HOF_PrintSpecial(BYREF HOF_Scores() AS UINTEGER, BYREF HOF_Names() AS STRING)
A "pretty High Score screen", that prints the top 10 scores.
Can probably be improved and made much more efficient. There are porbably bugs as well (for example not sure what would happen if you had 100 entries with a first high score of 10 ... i think it's probably overflow to 655555 etc. It includes string.bas and input.bas - not sure if the library needs both of those.