AgonConsole8 / agon-vdp

Official Firmware for the Agon Console8: ESP32 VDP
MIT License
38 stars 13 forks source link

Investigate looping in buffered commands #238

Open stevesims opened 1 month ago

stevesims commented 1 month ago

On discord, there was a query from @jblang about performing loops with buffered commands, where a relatively simple loop was failing to work

the assembler in question was as follows:

Main:
    call InitBuffer
    ld de, DrawLoopBuffer
    call CallBuffer
    call NewLine
    ret

; upload vdp draw command
InitBuffer:
    ld hl, DrawLoop
    ld de, DrawLoopBuffer
    ld bc, DrawLoopLength
    call ClearAndSendBuffer
    ret

DrawLoopBuffer: equ 0
DrawLoop:
    ; Escape the character and output it
    defb VduEscapeChar
DrawLoopCharOffset: equ $ - DrawLoop
    defb 0
    ; Increment target offset by ScreenWidth
    defb VduCommand, VduSystemCommand, VduBufferCommand ; 23, 0, &A0
    defw VduBufferSpecial   ; &FFFF
    defb VduBufferAdjust    ; 5
    defb VduBufferAdjustAdd ; 3
    defw DrawLoopCharOffset ; 1
    defb 1
    ; Conditionally jump to the same buffer while byte at DrawLoopCharOffset is non-zero
    defb VduCommand, VduSystemCommand, VduBufferCommand ; 23, 0, &A0
    defw VduBufferSpecial   ; &FFFF
    defb VduBufferConditionalJump   ; 8
    defb VduBufferConditionNotEqual ; 3
    defw DrawLoopBuffer
    defw DrawLoopCharOffset         ; 1
    defb 0
DrawLoopLength: equ $ - DrawLoop

it is a simple loop intended to display all characters (from 0-255)...

at a cursory look this should work - this issue is filed as a reference to go back and investigate this further when time permits