Jump to content
  • entries
    16
  • comments
    28
  • views
    30,722

Economical Initialization

Omegamatrix

750 views

A while back I did an entry on Faster Initialization for the 2600. Today's entry is about squeezing the bytes out of the Initialization routine to the bare minimum. Here is a routine I came up with a while back:

;Economical 8 byte initialization routine;By Omegamatrix    cld.loopClear:    ldx    #$0A          ; ASL opcode = $0A    inx    txs    pha    bne    .loopClear+1  ; jump between operator and operand to do ASL;A = 0;X = 0;Y = random;SP = $FF;Carry is clear

While there are no illegal opcodes used in this routine, there are still a few tricks:

 

1) The accumulator is never loaded. Instead it gets left shifted, and eventually after 8 shifts A=0.

2) The opcode for ASL is used to load the X register with 10 the first time through. Subsequent loops jump between the operator and operand for LDX #$0A to perform ASL.

3) The writes with PHA start at $0B (REFP0), but the TIA registers will all get cleared through their mirrored addresses at $40-$7F.

 SP    REGISTER    WRITE VALUE (FROM ACCUMULATOR, which gets ASL'd)$0B     REFP0      %XXXXXXXX   <--- first time through$0C     REFP1      %XXXXXXX0   <--- second pass, etc...$0D     PF0        %XXXXXX00$0E     PF1        %XXXXX000$0F     PF2        %XXXX0000$10     RESP0      %XXX00000$11     RESP1      %XX000000$12     RESM0      %X0000000$13     RESM1      %00000000$14     RESBL      A=0 for now on;writes continue to start of TIA mirrors SP    REGISTER    WRITE VALUE (FROM ACCUMULATOR)$40     VSYNC       0$41     VBLANK      0$42     WSYNC       0...;Writes continue through ZP $80-$FF clearing RIOT RAM;At end of routine TIA registers and RIOT RAM cleared,;A=X=0, SP = $FF, Y=random, Carry is clear 

You probably have noticed that I have skipped using SEI. I did this because there is no interrupt line on the 2600. However, there is always a chance one of the weird clones will. Insert SEI at the top of the initialization routine if you feel the need.



0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...