TTL Loaders and Zero Page

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
Post Reply
Phibrizzo
Posts: 84
Joined: 09 Nov 2022, 22:46

TTL Loaders and Zero Page

Post by Phibrizzo »

Hello :)

On my programs, very times i must initialize some variables on start program.
Something like that (example):

Code: Select all

_ORG    Main    ; start address of program

        LDWI    #$1000
        STW     #129    ; variable_1
        
        LDWI    #$FFFF
        STW     #131    ; variable_2
        
        LDWI    #$3333
        STW     #133    ; variable_3
        
        LDI     #10
        ST      #135    ; variable_4

; 19 byte
But i can do the same in this way:

Code: Select all

ORG     #129    ; variable address on Zero Page

        DC_W    #$1000  ; variable_1
        DC_W    #$FFFF  ; variable_2
        DC_W    #$3333  ; variable_3
        DC_B    #10     ; variable_4
        
; 7 bytes + 3 for load header = 10 bytes
In this method needed variables is initialize during load the program.
And the question is: which variables on Zero Page is used by the Loaders on Gigatron?
I dont want crash during load by overlapping data.
lb3361
Posts: 376
Joined: 17 Feb 2021, 23:07

Re: TTL Loaders and Zero Page

Post by lb3361 »

This is a tricky question, which depends a lot on the particular ROM.

Function `create_zpage_map` in the GLCC linker (see https://github.com/lb3361/gigatron-lcc/ ... nk.py#L522).

Here is the summary:
  • A GT1 file should never write to locations 0x00-0x2f which are critical for all ROMs.
  • A GT1 file could write value 0x01 to location 0x80 (but only value 0x01). This is useful because a GT1 file can only target a single segment in page 0.
  • A GT1 file that writes in 0x30-0x41 interferes with the operation of the Serial Loader on ROM<=v6. No longer true on ROM=dev7. Not sure for ROM=vx0. Note that one can still load such a file from the ROM (with SYS_Exec_88) and from the SPI SDCard.
  • A GT1 file that writes into the stack space (above vSP-60) interferes with the operation of the rom loader (SYS_Exec_88). No longer true on ROM=dev7. Not sure for ROM=vx0. Note that one can still load such a file with the Loader or from the SPI SDCard.
  • Some zero page locations do not interfere with the loading process, but the values written there will not last long if one uses ROM features that depend on these locations: e.g. : 0x30-0x35 for vIRQ on ROM>=v5a, 0x81-0x8f for vCPU7 registers on ROM=dev7, 0x82-0xcf for various ROM=vx0 goodies (to be verified). But they're available if one does not use the corresponding ROM features.
Conclusion: For best compatibility, do not write anything below 0x42 or above 0xc0. Best is to avoid writing above 0x80.
Phibrizzo
Posts: 84
Joined: 09 Nov 2022, 22:46

Re: TTL Loaders and Zero Page

Post by Phibrizzo »

Thank You for this big explonation.
Best is to avoid writing above 0x80.
You mean, writing above this address may be not safe for some ROMs. I understand.
lb3361
Posts: 376
Joined: 17 Feb 2021, 23:07

Re: TTL Loaders and Zero Page

Post by lb3361 »

Phibrizzo wrote: 31 Jul 2024, 12:53 You mean, writing above this address may be not safe for some ROMs. I understand.
I mean that you should first use the 62 bytes in [0x42-0x7f] because this is safe in all cases I know. Your program can also use [0x36-0x41] but you should not load values into these locations because that interferes with the loader. Make that [0x30-0x41] if you do not use vIRQ.

Then it depends on both the ROM you target and the ROMs people use to run your program. As long as you target ROMv6 or earlier, you will not use the vX0 or DEV7 extensions, and you can safely use [0x81-0xcf], even if running on vX0 or DEV7. To do so in a single segment you probably need to load 0x80 also, which is okay as long as you set it to value 0x1. The higher you go in page zero, the more you risk encroaching on the stack.

If you target vX0 or DEV7, you have new possibilities and new constraints. For instance, if you target DEV7, you can load values into [0x30-0x41] but your program should avoid using [0x81-0x8f] which contain extended vCPU registers. However you can also move the stack elsewhere in memory, making locations above 0xd0 available for use.
Phibrizzo
Posts: 84
Joined: 09 Nov 2022, 22:46

Re: TTL Loaders and Zero Page

Post by Phibrizzo »

Thanks again :)

Now i added new feature to my compiler.
For this moment for declaration of variables i did semething like this:

Code: Select all

; declaration of pointers

_VAR    var0    0x42
_VAR    var1    0x44
....

        LDWI    #$5566
        STW     var0

        LDI     #$ff
        ST      var1
Now i can do the same in this way:

Code: Select all

; declaration of varialbles
; p = 0x42 - start pointer declarated in compiler

WORD    var0    #$5566  ; (*p) = #$5566, p+=2
BYTE    var1    #$ff    ; (*p) = #$FF,   p++
Now compiler generated automatically initiation variables data and adds them to final gt1 file.
Now declaration is easer and final file can be few bytes shorter.
Post Reply