Код:
asm(
"\
#mov $MSG000, R0 \n\
#emt $0351 # .print hello world \n\
# \n\
# init screen \n\
mov $0B1000100010001000, PAL01+2 # palette 1st word \n\
mov $0B1111100010001000, PAL02+2 # palette 2nd word \n\
mov $0B0000000000010000, RES01+2 # cursor \n\
mov $0B0000000000010111, RES02+2 # resolution & luminance \n\
mov $PPUSTA, R4 # PPU code addr \n\
# mov $<PPUEND-PPUSTA/2>, R5 # PPU code length in words \n\
# dont know how to write that in gcc asm \n\
mov $PPUEND, R5 \n\
sub $PPUSTA, R5 \n\
clc \n\
ror R5 \n\
jsr PC, PPRUN # allocate PPU memory, copy, run \n\
jsr PC, PPRELE # release PPU memory \n\
# init screen end \n\
# \n\
emt $0350 # .exit \n\
\n\
MSG000: .asciz \"Hello world!\" \n\
.even \n\
\n\
# PPU message \n\
PPMSG: .WORD PPARR # address of beginning of array \n\
.WORD 0177777 # end of transmission \n\
\n\
# PPU data exchange array \n\
PPARR: .BYTE 0 # return value (0 - OK) \n\
PPCMD: .BYTE 0 # command \n\
.WORD 032 # device type (032 - PPU mem) \n\
PPAPP: .WORD 0 # address for PPU \n\
PPACP: .WORD 0 # address for CPU \n\
PPLEN: .WORD 0 # length in words \n\
\n\
# send command to PPU \n\
PPSEN: mov R0, -(SP) \n\
mov R1, -(SP) \n\
mov $PPMSG, R0 # array address \n\
mov $05, R1 # bytes to send+1 (sending from PPMSG) \n\
br 1$ \n\
2$: movb (R0)+, @$0176676 \n\
1$: tstb @$0176674 # test if we are ready to send \n\
bpl 1$ # cycle if >= 0 (not set last bit in byte) \n\
sob R1, 2$ \n\
mov (SP)+, R1 \n\
mov (SP)+, R0 \n\
rts PC \n\
\n\
# send and start PPU code \n\
# R4 - start addr in CPU \n\
# R5 - length / 2 \n\
PPRUN: movb $1, PPCMD # 1 - allocate memory \n\
mov R5, PPLEN \n\
jsr PC, PPSEN \n\
tstb PPARR # test if allocate success \n\
beq 1$ # 0 - OK \n\
rts PC \n\
1$: movb $020, PPCMD # 20 - write to PPU mem \n\
mov R5, PPLEN \n\
mov R4, PPACP \n\
jsr PC, PPSEN \n\
movb $030, PPCMD # 30 - run \n\
jsr PC, PPSEN \n\
rts PC \n\
\n\
# release PPU memory in case of something.. \n\
PPRELE: movb $2, PPCMD # 2 - release memory \n\
jsr PC, PPSEN \n\
rts PC \n\
\n\
####### PPU CODE HERE ####### \n\
PPUSTA: jsr PC, PPCLRV \n\
# construct our own lines table \n\
mov PC, R0 \n\
add $PPLIN1-., R0 \n\
add $010, R0 # align addr with 8. bytes \n\
bic $07, R0 \n\
mov R0, R2 # save addr and use later \n\
# 1st element - set palette (YRGB YRGB YRGB YRGB) \n\
PAL01: mov $0B1101110010011000, (R0)+ \n\
PAL02: mov $0B1111111010111010, (R0)+ \n\
clr (R0)+ # vaddr is not used here \n\
mov R0, (R0) # next element addr \n\
add $2, (R0) # \n\
bis $2, (R0)+ # 2 = 010 - next element is scale&cursor \n\
# 2nd line - set scale, lumi and cursor \n\
RES01: mov $0B0000000000010000, (R0)+ # no cursor \n\
RES02: mov $0B0000000000010111, (R0)+ # 320x288, max luminance (..00111-640, ..10111 - 320)\n\
clr (R0)+ # vaddr is not used here \n\
mov R0, (R0) \n\
add $2, (R0)+ # next element is 2-words \n\
# 16 not used lines \n\
mov $16, R3 \n\
10$: clr (R0)+ \n\
mov R0, (R0) \n\
add $2, (R0)+ \n\
sob R3, 10$ \n\
# next 288 'main' lines from top \n\
mov $0100000, R1 \n\
mov $288, R3 \n\
20$: mov R1, (R0)+ \n\
mov R0, (R0) \n\
add $2, (R0)+ \n\
add $80, R1 \n\
sob R3, 20$ \n\
# set new lines table \n\
clr @$0270 \n\
bis $06, R2 # first line is palette \n\
mov R2, @$0272 # saved addr \n\
rts PC \n\
\n\
# clear vram \n\
PPCLRV: mov $0177010, R4 \n\
mov $0177012, R2 \n\
mov $0177014, R5 \n\
mov $0100000, R3 \n\
mov R3, (R4) \n\
30$: clr (R2) \n\
clr (R5) \n\
inc (R4) \n\
sob R3, 30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