1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-27 09:31:18 +00:00

Added Atari 8bit rasterbar example.

This commit is contained in:
jespergravgaard 2020-08-17 01:10:02 +02:00
parent bd1c4bcd13
commit 1c368b9c5e
8 changed files with 1482 additions and 2 deletions

View File

@ -6,10 +6,10 @@
#include <atari-pokey.h>
// Atari GTIA write registers
struct ATARI_GTIA_WRITE * const TIA = 0xd000;
struct ATARI_GTIA_WRITE * const GTIA = 0xd000;
// Atari GTIA read registers
struct ATARI_GTIA_READ * const TIA_READ = 0xd000;
struct ATARI_GTIA_READ * const GTIA_READ = 0xd000;
// Atari POKEY write registers
struct ATARI_POKEY_WRITE * const POKEY = 0xd200;

View File

@ -202,6 +202,11 @@ public class TestPrograms {
compileAndCompare("examples/mega65/hello-mega65.c");
}
@Test
public void testAtariXlRasterbars() throws IOException, URISyntaxException {
compileAndCompare("examples/atarixl/rasterbars.c");
}
@Test
public void testAtariXlHello() throws IOException, URISyntaxException {
compileAndCompare("examples/atarixl/helloxl.c");

View File

@ -110,6 +110,7 @@
"command": "~/c64/kickc_local/bin/kickc.sh",
"args": [
"-vasmout",
"-Oloophead"
"-Sc",
"-odir",
"~/c64/tmp/",

View File

@ -0,0 +1,47 @@
// Raster Bars for Atari XL / XE
#pragma target(atarixl)
#pragma emulator("65XEDebugger")
#include <atari-xl.h>
void main() {
// Disable IRQ
asm { sei }
// Enable DMA, Narrow Playfield - ANTIC Direct Memory Access Control
ANTIC->DMACTL = 0x21;
// Set ANTIC Display List Pointer
ANTIC->DLIST = DISPLAY_LIST;
// Set colors
GTIA->COLPF0 = 0x28;
GTIA->COLPF1 = 0x48;
GTIA->COLPF2 = 0x80;
GTIA->COLPF3 = 0xc8;
// Loop forever - Display raster bars
char col = 0;
for(;;) {
while(ANTIC->VCOUNT!=40) ;
char c = col++;
for( char l=0;l<100;l++) {
ANTIC->WSYNC = c;
GTIA->COLBK = c;
c++;
}
GTIA->COLBK = 0;
};
}
// Message to show
char TEXT[] = "HELLO atari 8BIT"
"Demonstrates ANTIC display list!"
;
// ANTIC Display List Program
// https://en.wikipedia.org/wiki/ANTIC
char DISPLAY_LIST[] = {
BLANK8, BLANK8, BLANK8, // 3* 8 blank lines
LMS|MODE7, <TEXT, >TEXT, // Load memory address and set to charmode 7 (16/20/24 chars wide, 16 lines per char)
BLANK4, // 4 blank lines
MODE2, // Charmode 2 (32/40/48 chars wide, 8 lines per char)
JVB, <DISPLAY_LIST, >DISPLAY_LIST // Wait for VBLANK and jump
};

View File

@ -0,0 +1,117 @@
// Raster Bars for Atari XL / XE
// Atari XL/XE XEX file minimal file
// https://www.atarimax.com/jindroush.atari.org/afmtexe.html
.file [name="rasterbars.xex", type="bin", segments="XexFile"]
.segmentdef XexFile
.segment XexFile
// Binary File Header
.byte $ff, $ff
// Program segment [start address, end address, data]
.word ProgramStart, ProgramEnd-1
.segmentout [ segments="Program" ]
// RunAd - Run Address Segment [start address, end address, data]
.word $02e0, $02e1
.word main
.segmentdef Program [segments="ProgramStart, Code, Data, ProgramEnd"]
.segmentdef ProgramStart [start=$2000]
.segment ProgramStart
ProgramStart:
.segmentdef Code [startAfter="ProgramStart"]
.segmentdef Data [startAfter="Code"]
.segmentdef ProgramEnd [startAfter="Data"]
.segment ProgramEnd
ProgramEnd:
// 2: High Resolution Text Mode. 8 scanlines per char, 32/40/48 chars wide. bit 7 controls inversion or blinking, based on modes in CHACTL.
.const MODE2 = 2
// 7: Single color text in five colors. 16 scanlines per char, 16/20/24 chars wide. the upper two bits are used to select the foreground color used by 1 bits, with 00-11 producing PF0-PF3.
.const MODE7 = 7
// Load memory scan counter (LMS operation) - Load memory scan counter with new 16-bit address. Can be combined with mode instructions by OR.
.const LMS = $40
// Jump and wait for Vertical Blank - suspends the display list until vertical blank and then jumps. This is usually used to terminate the display list and restart it for the next frame.
.const JVB = $41
// Blank 4 lines
.const BLANK4 = $30
// Blank 8 lines
.const BLANK8 = $70
.const OFFSET_STRUCT_ATARI_ANTIC_DLIST = 2
.const OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF0 = $16
.const OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF1 = $17
.const OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF2 = $18
.const OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF3 = $19
.const OFFSET_STRUCT_ATARI_ANTIC_VCOUNT = $b
.const OFFSET_STRUCT_ATARI_ANTIC_WSYNC = $a
.const OFFSET_STRUCT_ATARI_GTIA_WRITE_COLBK = $1a
// Atari GTIA write registers
.label GTIA = $d000
// Atari ANTIC registers
.label ANTIC = $d400
.segment Code
main: {
// asm
// Disable IRQ
sei
// ANTIC->DMACTL = 0x21
// Enable DMA, Narrow Playfield - ANTIC Direct Memory Access Control
lda #$21
sta ANTIC
// ANTIC->DLIST = DISPLAY_LIST
// Set ANTIC Display List Pointer
lda #<DISPLAY_LIST
sta ANTIC+OFFSET_STRUCT_ATARI_ANTIC_DLIST
lda #>DISPLAY_LIST
sta ANTIC+OFFSET_STRUCT_ATARI_ANTIC_DLIST+1
// GTIA->COLPF0 = 0x28
// Set colors
lda #$28
sta GTIA+OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF0
// GTIA->COLPF1 = 0x48
lda #$48
sta GTIA+OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF1
// GTIA->COLPF2 = 0x80
lda #$80
sta GTIA+OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF2
// GTIA->COLPF3 = 0xc8
lda #$c8
sta GTIA+OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF3
ldy #0
__b1:
// while(ANTIC->VCOUNT!=40)
lda #$28
cmp ANTIC+OFFSET_STRUCT_ATARI_ANTIC_VCOUNT
bne __b1
// c = col++
tya
tax
inx
lda #0
__b3:
// for( char l=0;l<100;l++)
cmp #$64
bcc __b4
// GTIA->COLBK = 0
lda #0
sta GTIA+OFFSET_STRUCT_ATARI_GTIA_WRITE_COLBK
txa
tay
jmp __b1
__b4:
// ANTIC->WSYNC = c
sty ANTIC+OFFSET_STRUCT_ATARI_ANTIC_WSYNC
// GTIA->COLBK = c
sty GTIA+OFFSET_STRUCT_ATARI_GTIA_WRITE_COLBK
// c++;
iny
// for( char l=0;l<100;l++)
clc
adc #1
jmp __b3
}
.segment Data
// Message to show
.encoding "ascii"
TEXT: .text @"\$28\$25\$2c\$2c\$2f\$00atari\$00\$18\$22\$29\$34\$24emonstrates\$00\$21\$2e\$34\$29\$23\$00display\$00list\$01"
.byte 0
// ANTIC Display List Program
// https://en.wikipedia.org/wiki/ANTIC
DISPLAY_LIST: .byte BLANK8, BLANK8, BLANK8, LMS|MODE7, <TEXT, >TEXT, BLANK4, MODE2, JVB, <DISPLAY_LIST, >DISPLAY_LIST

View File

@ -0,0 +1,33 @@
(void()) main()
main: scope:[main] from
asm { sei }
[1] *((byte*)(const nomodify struct ATARI_ANTIC*) ANTIC) ← (byte) $21
[2] *((byte**)(const nomodify struct ATARI_ANTIC*) ANTIC+(const byte) OFFSET_STRUCT_ATARI_ANTIC_DLIST) ← (const byte*) DISPLAY_LIST
[3] *((byte*)(const nomodify struct ATARI_GTIA_WRITE*) GTIA+(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF0) ← (byte) $28
[4] *((byte*)(const nomodify struct ATARI_GTIA_WRITE*) GTIA+(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF1) ← (byte) $48
[5] *((byte*)(const nomodify struct ATARI_GTIA_WRITE*) GTIA+(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF2) ← (byte) $80
[6] *((byte*)(const nomodify struct ATARI_GTIA_WRITE*) GTIA+(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF3) ← (byte) $c8
to:main::@1
main::@1: scope:[main] from main main::@1 main::@5
[7] (byte) main::col#2 ← phi( main/(byte) 0 main::@1/(byte) main::col#2 main::@5/(byte) main::col#8 )
[8] if(*((byte*)(const nomodify struct ATARI_ANTIC*) ANTIC+(const byte) OFFSET_STRUCT_ATARI_ANTIC_VCOUNT)!=(byte) $28) goto main::@1
to:main::@2
main::@2: scope:[main] from main::@1
[9] (byte) main::col#1 ← ++ (byte) main::col#2
to:main::@3
main::@3: scope:[main] from main::@2 main::@4
[10] (byte) main::c#2 ← phi( main::@2/(byte) main::col#2 main::@4/(byte) main::c#1 )
[10] (byte) main::l#2 ← phi( main::@2/(byte) 0 main::@4/(byte) main::l#1 )
[11] if((byte) main::l#2<(byte) $64) goto main::@4
to:main::@5
main::@5: scope:[main] from main::@3
[12] *((byte*)(const nomodify struct ATARI_GTIA_WRITE*) GTIA+(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLBK) ← (byte) 0
[13] (byte) main::col#8 ← (byte) main::col#1
to:main::@1
main::@4: scope:[main] from main::@3
[14] *((byte*)(const nomodify struct ATARI_ANTIC*) ANTIC+(const byte) OFFSET_STRUCT_ATARI_ANTIC_WSYNC) ← (byte) main::c#2
[15] *((byte*)(const nomodify struct ATARI_GTIA_WRITE*) GTIA+(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLBK) ← (byte) main::c#2
[16] (byte) main::c#1 ← ++ (byte) main::c#2
[17] (byte) main::l#1 ← ++ (byte) main::l#2
to:main::@3

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,139 @@
(const nomodify struct ATARI_ANTIC*) ANTIC = (struct ATARI_ANTIC*) 54272
(byte) ATARI_ANTIC::CHACTL
(byte) ATARI_ANTIC::CHBASE
(byte*) ATARI_ANTIC::DLIST
(byte) ATARI_ANTIC::DMACTL
(byte) ATARI_ANTIC::HSCROL
(byte) ATARI_ANTIC::NMIEN
(byte) ATARI_ANTIC::NMIST
(byte) ATARI_ANTIC::PENH
(byte) ATARI_ANTIC::PENV
(byte) ATARI_ANTIC::PMBASE
(byte) ATARI_ANTIC::UNUSED1
(byte) ATARI_ANTIC::UNUSED2
(byte) ATARI_ANTIC::VCOUNT
(byte) ATARI_ANTIC::VSCROL
(byte) ATARI_ANTIC::WSYNC
(byte) ATARI_GTIA_READ::CONSOL
(byte) ATARI_GTIA_READ::M0PF
(byte) ATARI_GTIA_READ::M0PL
(byte) ATARI_GTIA_READ::M1PF
(byte) ATARI_GTIA_READ::M1PL
(byte) ATARI_GTIA_READ::M2PF
(byte) ATARI_GTIA_READ::M2PL
(byte) ATARI_GTIA_READ::M3PF
(byte) ATARI_GTIA_READ::M3PL
(byte) ATARI_GTIA_READ::P0PF
(byte) ATARI_GTIA_READ::P0PL
(byte) ATARI_GTIA_READ::P1PF
(byte) ATARI_GTIA_READ::P1PL
(byte) ATARI_GTIA_READ::P2PF
(byte) ATARI_GTIA_READ::P2PL
(byte) ATARI_GTIA_READ::P3PF
(byte) ATARI_GTIA_READ::P3PL
(byte) ATARI_GTIA_READ::PAL
(byte) ATARI_GTIA_READ::TRIG0
(byte) ATARI_GTIA_READ::TRIG1
(byte) ATARI_GTIA_READ::TRIG2
(byte) ATARI_GTIA_READ::TRIG3
(const byte*) ATARI_GTIA_READ::UNUSED[(number) $a] = { fill( $a, 0) }
(byte) ATARI_GTIA_WRITE::COLBK
(byte) ATARI_GTIA_WRITE::COLPF0
(byte) ATARI_GTIA_WRITE::COLPF1
(byte) ATARI_GTIA_WRITE::COLPF2
(byte) ATARI_GTIA_WRITE::COLPF3
(byte) ATARI_GTIA_WRITE::COLPM0
(byte) ATARI_GTIA_WRITE::COLPM1
(byte) ATARI_GTIA_WRITE::COLPM2
(byte) ATARI_GTIA_WRITE::COLPM3
(byte) ATARI_GTIA_WRITE::CONSPK
(byte) ATARI_GTIA_WRITE::GRACTL
(byte) ATARI_GTIA_WRITE::GRAFM
(byte) ATARI_GTIA_WRITE::GRAFP0
(byte) ATARI_GTIA_WRITE::GRAFP1
(byte) ATARI_GTIA_WRITE::GRAFP2
(byte) ATARI_GTIA_WRITE::GRAFP3
(byte) ATARI_GTIA_WRITE::HITCLR
(byte) ATARI_GTIA_WRITE::HPOSM0
(byte) ATARI_GTIA_WRITE::HPOSM1
(byte) ATARI_GTIA_WRITE::HPOSM2
(byte) ATARI_GTIA_WRITE::HPOSM3
(byte) ATARI_GTIA_WRITE::HPOSP0
(byte) ATARI_GTIA_WRITE::HPOSP1
(byte) ATARI_GTIA_WRITE::HPOSP2
(byte) ATARI_GTIA_WRITE::HPOSP3
(byte) ATARI_GTIA_WRITE::PRIOR
(byte) ATARI_GTIA_WRITE::SIZEM
(byte) ATARI_GTIA_WRITE::SIZEP0
(byte) ATARI_GTIA_WRITE::SIZEP1
(byte) ATARI_GTIA_WRITE::SIZEP2
(byte) ATARI_GTIA_WRITE::SIZEP3
(byte) ATARI_GTIA_WRITE::VDELAY
(byte) ATARI_POKEY_READ::ALLPOT
(byte) ATARI_POKEY_READ::IRQST
(byte) ATARI_POKEY_READ::KBCODE
(byte) ATARI_POKEY_READ::POT0
(byte) ATARI_POKEY_READ::POT1
(byte) ATARI_POKEY_READ::POT2
(byte) ATARI_POKEY_READ::POT3
(byte) ATARI_POKEY_READ::POT4
(byte) ATARI_POKEY_READ::POT5
(byte) ATARI_POKEY_READ::POT6
(byte) ATARI_POKEY_READ::POT7
(byte) ATARI_POKEY_READ::RANDOM
(byte) ATARI_POKEY_READ::SERIN
(byte) ATARI_POKEY_READ::SKSTAT
(const byte*) ATARI_POKEY_READ::UNUSED[(number) 2] = { fill( 2, 0) }
(byte) ATARI_POKEY_WRITE::AUDC1
(byte) ATARI_POKEY_WRITE::AUDC2
(byte) ATARI_POKEY_WRITE::AUDC3
(byte) ATARI_POKEY_WRITE::AUDC4
(byte) ATARI_POKEY_WRITE::AUDCTL
(byte) ATARI_POKEY_WRITE::AUDF1
(byte) ATARI_POKEY_WRITE::AUDF2
(byte) ATARI_POKEY_WRITE::AUDF3
(byte) ATARI_POKEY_WRITE::AUDF4
(byte) ATARI_POKEY_WRITE::IRQEN
(byte) ATARI_POKEY_WRITE::POTGO
(byte) ATARI_POKEY_WRITE::SEROUT
(byte) ATARI_POKEY_WRITE::SKCTL
(byte) ATARI_POKEY_WRITE::SKREST
(byte) ATARI_POKEY_WRITE::STIMER
(byte) ATARI_POKEY_WRITE::UNUSED
(const nomodify byte) BLANK4 = (byte) $30
(const nomodify byte) BLANK8 = (byte) $70
(const byte*) DISPLAY_LIST[] = { (const nomodify byte) BLANK8, (const nomodify byte) BLANK8, (const nomodify byte) BLANK8, (const nomodify byte) LMS|(const nomodify byte) MODE7, <(const byte*) TEXT, >(const byte*) TEXT, (const nomodify byte) BLANK4, (const nomodify byte) MODE2, (const nomodify byte) JVB, <(const byte*) DISPLAY_LIST, >(const byte*) DISPLAY_LIST }
(const nomodify struct ATARI_GTIA_WRITE*) GTIA = (struct ATARI_GTIA_WRITE*) 53248
(const nomodify byte) JVB = (byte) $41
(const nomodify byte) LMS = (byte) $40
(const nomodify byte) MODE2 = (byte) 2
(const nomodify byte) MODE7 = (byte) 7
(const byte) OFFSET_STRUCT_ATARI_ANTIC_DLIST = (byte) 2
(const byte) OFFSET_STRUCT_ATARI_ANTIC_VCOUNT = (byte) $b
(const byte) OFFSET_STRUCT_ATARI_ANTIC_WSYNC = (byte) $a
(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLBK = (byte) $1a
(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF0 = (byte) $16
(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF1 = (byte) $17
(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF2 = (byte) $18
(const byte) OFFSET_STRUCT_ATARI_GTIA_WRITE_COLPF3 = (byte) $19
(const byte*) TEXT[] = (byte*) "HELLO atari 8BITDemonstrates ANTIC display list!"sa
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(byte) main::c
(byte) main::c#1 reg byte y 101.0
(byte) main::c#2 reg byte y 103.75
(byte) main::col
(byte) main::col#1 reg byte x 2.75
(byte) main::col#2 reg byte y 78.33333333333334
(byte) main::col#8 reg byte y 22.0
(byte) main::l
(byte) main::l#1 reg byte a 202.0
(byte) main::l#2 reg byte a 60.599999999999994
reg byte a [ main::l#2 main::l#1 ]
reg byte y [ main::c#2 main::col#2 main::col#8 main::c#1 ]
reg byte x [ main::col#1 ]