After the previous post we have code that can output directly from program memory. What we need now is some code to output from RAM.

The reason we want to output from RAM is so that we can use overlays and the occasional custom (dynamic) tile. To make it as simple as possible we want it to output at the same speed as the other part of the code. As said I came up with a solution to jump to the RAM output by checking whether the LSB (least significant bit) was set. This works because program memory is always at even address’. Therefore to make the code jump the tile needs to be set as a odd number.

outputdataRAM:
tst r16 ;1
out RGBPORT,r7 ;1
brne outputdataEnd ;2/1
swap r7 ;1
ld ZL,X+ ;2
out RGBPORT,r7 ;1
ld r7, Y+ ;2
ld ZH,X+ ;2
out RGBPORT,r7
swap r7 ;1
add ZL,r5 ;1
adc ZH,r6 ;1
nop
out RGBPORT,r7
ld r7, Y+ ;2
nop
nop
out RGBPORT,r7
swap r7 ;1
lpm r4,Z+ ;3
out RGBPORT,r7 ;1
ld r7, Y+ ;2
nop
nop
out RGBPORT,r7
swap r7 ;1
nop
nop
dec r16 ;1
out RGBPORT,r7
ld r7,Y+ ;2
brne outputdata ;2/1
outputdataEnd:

The above code should do as we want except for the minor problem of if there are two RAM tiles next to each other. It seems I will have to keep thinking for coming up with a better solution. For now though I am just going to assume that there is not two tiles in RAM next to each other.

Advertisements