Skip to content

Instantly share code, notes, and snippets.

@lucasw
Last active May 2, 2017 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasw/5ddd9a8b28ca48005bbb9291fc49f5e1 to your computer and use it in GitHub Desktop.
Save lucasw/5ddd9a8b28ca48005bbb9291fc49f5e1 to your computer and use it in GitHub Desktop.
atari 2600 with ca65

Can use ca65 (instead of dasm):

http://wiki.cc65.org/doku.php?id=cc65:atari_2600

Need vcs.h and macro.h from dasm https://github.com/munsie/dasm/tree/master/machines/atari2600 No they don't compile, just start a new vcs.inc that defines all the registers using http://www.classic-games.com/atari2600/specs.html.

Adapt http://www.randomterrain.com/atari-2600-memories-tutorial-andrew-davie-08.html assembly example to ca65.

This produces demo.o

$HOME/other/cc65/bin/ca65 -g -o demo.o demo.s -I.
$HOME/other/cc65/bin/ld65 -C atari2600.cfg -m demo.map -Ln demo.labels -vm demo.o -o demo.bin
@lucasw
Copy link
Author

lucasw commented Apr 22, 2017

Currently this builds a bin, but it doesn't run in stella

It looks identical to http://www.randomterrain.com/files_andrew_davie_sessions/kernel_01.bin except that unused memory isn't filled with 0xff, and in the stella debugger it looks completely different.

look at http://svolli.de/atari2600/28c3intro.tar.bz2 from http://svolli.de/atari2600/

@lucasw
Copy link
Author

lucasw commented Apr 22, 2017

look at http://svolli.de/atari2600/28c3intro.tar.bz2 from http://svolli.de/atari2600/

(use their vcs.inc)

ca65 -g -o obj/charset.o   charset.s
ca65 -g -o obj/scrolltables.o   scrolltables.s
ca65 -g -o obj/vectors.o   vectors.s
ca65 -g -o obj/help.o   help.s
ca65 -g -o obj/logodraw.o   logodraw.s
ca65 -g -o obj/scrollline.o   scrollline.s
ca65 -g -o obj/beamrider.o   beamrider.s
ca65 -g -o obj/main.o   main.s
ca65 -g -o obj/logodata.o   logodata.s
ld65  -Catari2600.cfg -m obj/28c3intro.map -Ln obj/28c3intro.labels -vm  obj/charset.o obj/scrolltables.o obj/vectors.o obj/help.o obj/logodraw.o obj/scrollline.o obj/beamrider.o obj/main.o obj/logodata.o  -o 28c3intro.bin

No ld65: Warning: demo.cfg(21): Segment VECTORS' does not exist` warning from this, but the cfg is the same.

Need this:

.segment "VECTORS" 
.addr Reset ; NMI: should never occur 
.addr Reset ; RESET 
.addr Reset ; IRQ: will only occur with brk 

Now the bin is 4096 bytes and is filled with 00 (rather than 0xff in the kernel_01.bin) - and it works in stella!

@lucasw
Copy link
Author

lucasw commented Apr 22, 2017

This is the working adapted example:

.setcpu "6502" 
.include "vcs.inc" 
.segment "CODE" 
;.org $F000 
Reset: 
StartOfFrame: 
; Start of vertical blank processing 
lda #0 
sta VBLANK 
lda #2 
sta VSYNC 
 
; 3 scanlines of VSYNCH signal... 
.repeat 3 
sta WSYNC 
.endrepeat 
lda #0 
sta VSYNC 
; 37 scanlines of vertical blank... 
.repeat 37 
sta WSYNC 
.endrepeat 
 
; 192 scanlines of picture... 
 
ldx #0 
.repeat 192 ; scanlines 
inx 
stx COLUBK 
sta WSYNC 
.endrepeat 
 
lda #%01000010 
sta VBLANK                     ; end of screen - enter blanking 
; 30 scanlines of overscan... 
.repeat 30 
sta WSYNC 
.endrepeat 
jmp StartOfFrame 
; fill in the rest of the address space? 
.org $FFFA 
.segment "VECTORS"  
.addr Reset ; NMI: should never occur  
.addr Reset ; RESET  
.addr Reset ; IRQ: will only occur with brk  

@lucasw
Copy link
Author

lucasw commented Apr 22, 2017

@lucasw
Copy link
Author

lucasw commented May 2, 2017

Stella emulator

https://stella-emu.github.io

https://github.com/stella-emu/stella

Needs update to CMake?

Can't build out of source (only config.mak is put into out of source dir)

Incompatible with ca65 list/symbols for helping with debugging?

Debugging toggle backtick button toggles too fast, need to slow it down or make it two non-toggle buttons.
-> The latest github stella doesn't have this problem, backtick has to be released first. So need to get that version into Ubuntu.

@lucasw
Copy link
Author

lucasw commented May 2, 2017

Example ca65 label file:

al 000080 .__BSS_LOAD__
al 000080 .__BSS_RUN__
al 000000 .__BSS_SIZE__
al 00F072 .__CODE_LOAD__
al 00F072 .__CODE_RUN__
al 000213 .__CODE_SIZE__
al 00F285 .__DATA_LOAD__
al 000080 .__DATA_RUN__
al 000000 .__DATA_SIZE__
al 000000 .__RAM_FILEOFFS__
al 000080 .__RAM_LAST__
al 000080 .__RAM_SIZE__
al 000080 .__RAM_START__
al 001000 .__RIOT_FILEOFFS__
al 000280 .__RIOT_LAST__
al 000020 .__RIOT_SIZE__
al 000280 .__RIOT_START__
al 000000 .__ROM_FILEOFFS__
al 010000 .__ROM_LAST__
al 001000 .__ROM_SIZE__
al 00F000 .__ROM_START__
al 001000 .__TIA_FILEOFFS__
al 000000 .__TIA_LAST__
al 000040 .__TIA_SIZE__
al 000000 .__TIA_START__
al 00F049 .digit_9
al 00F041 .digit_8
al 00F039 .digit_7
al 00F031 .digit_6

Example map file

Modules list:
-------------
demo.o:
    CODE              Offs=000000  Size=000213  Align=00001  Fill=0000
    RODATA            Offs=000000  Size=000072  Align=00001  Fill=0000
    BSS               Offs=000000  Size=000000  Align=00001  Fill=0000
    DATA              Offs=000000  Size=000000  Align=00001  Fill=0000
    ZEROPAGE          Offs=000000  Size=000000  Align=00001  Fill=0000
    NULL              Offs=000000  Size=000000  Align=00001  Fill=0000
    VECTORS           Offs=000000  Size=000006  Align=00001  Fill=0000


Segment list:
-------------
Name                   Start     End    Size  Align
----------------------------------------------------
NULL                  000000  000000  000000  00001
BSS                   000080  000080  000000  00001
DATA                  000080  000080  000000  00001
ZEROPAGE              000080  000080  000000  00001
RODATA                00F000  00F071  000072  00001
CODE                  00F072  00F284  000213  00001
VECTORS               00FFFA  00FFFF  000006  00001


Exports list by name:
---------------------
__BSS_LOAD__              000080  LA    __BSS_RUN__               000080  LA    
__BSS_SIZE__              000000  EA    __CODE_LOAD__             00F072  LA    
__CODE_RUN__              00F072  LA    __CODE_SIZE__             000213  EA    
__DATA_LOAD__             00F285  LA    __DATA_RUN__              000080  LA    
__DATA_SIZE__             000000  EA    __RAM_FILEOFFS__          000000  EA    
__RAM_LAST__              000080  LA    __RAM_SIZE__              000080  EA    
__RAM_START__             000080  LA    __RIOT_FILEOFFS__         001000  EA    
__RIOT_LAST__             000280  LA    __RIOT_SIZE__             000020  EA    
__RIOT_START__            000280  LA    __ROM_FILEOFFS__          000000  EA    
__ROM_LAST__              010000  LA    __ROM_SIZE__              001000  EA    
__ROM_START__             00F000  LA    __TIA_FILEOFFS__          001000  EA    
__TIA_LAST__              000000  LA    __TIA_SIZE__              000040  EA    
__TIA_START__             000000  LA    


Exports list by value:
----------------------
__BSS_SIZE__              000000  EA    __DATA_SIZE__             000000  EA    
__RAM_FILEOFFS__          000000  EA    __ROM_FILEOFFS__          000000  EA    
__TIA_LAST__              000000  LA    __TIA_START__             000000  LA    

@lucasw
Copy link
Author

lucasw commented May 2, 2017

What do dasm equivalents look like?
dasm is still on sourceforge.net, but https://github.com/munsie/dasm may be the same.

Built the test

~/other/retro/atari/dasm/test/atari2600$ ../../bin/dasm boing26.asm -f3 -I../../machines/atari2600/ -oboing26.bin -lboing26.sym -sboing26.lst

map file:

--- Symbol List (sorted by symbol)
Audc0                    0015              (R )
Audc1                    0016              (R )
Audf0                    0017              (R )
Audf1                    0018              (R )
Audv0                    0019              (R )
Audv1                    001a              (R )
BottomDelay              0090              (R )
Cart_Init                f000              (R )
ChangeNote               f2f4              (R )
CheckEgg                 f343              (R )
ColuBK                   0009              (R )
ColuP0                   0006              (R )
ColuP1                   0007              (R )
Colupf                   0008                  
Common_Init              f005                  
Ctrlpf                   000a                  
Cxblpf                   0006                  
Cxclr                    002c                  
Cxm0fb                   0004                  
Cxm0p                    0000                  
Cxm1fb                   0005                  
Cxm1p                    0001                  
Cxp0fb                   0002                  
Cxp1fb                   0003                  
Cxppmm                   0007                  
D1                       f185              (R )
DelayPTR                 008c              (R )
DemoInit                 f01e                  
DoSound                  f29c              (R )
DoVoice1                 f322              (R )
DoVoice2                 f311                  
...

sym file

------- FILE boing26.asm LEVEL 1 PASS 2
      1  10000 ????
      2  10000 ????              processor  6502
      3  10000 ????
      4  10000 ????           ; TIA (Stella) write-only registers^M
      5  10000 ????           ;^M
      6  10000 ????   00 00     Vsync      equ  $00
      7  10000 ????   00 01     Vblank     equ  $01
      8  10000 ????   00 02     Wsync      equ  $02
      9  10000 ????   00 03     Rsync      equ  $03
     10  10000 ????   00 04     Nusiz0     equ  $04
     11  10000 ????   00 05     Nusiz1     equ  $05
     12  10000 ????   00 06     ColuP0     equ  $06
     13  10000 ????   00 07     ColuP1     equ  $07
     14  10000 ????   00 08     Colupf     equ  $08
     15  10000 ????   00 09     ColuBK     equ  $09
     16  10000 ????   00 0a     Ctrlpf     equ  $0A
     17  10000 ????   00 0b     Refp0      equ  $0B
     18  10000 ????   00 0c     Refp1      equ  $0C
     19  10000 ????   00 0d     Pf0        equ  $0D
     20  10000 ????   00 0e     Pf1        equ  $0E
     21  10000 ????   00 0f     Pf2        equ  $0F
     22  10000 ????   00 10     RESP0      equ  $10
...

@lucasw
Copy link
Author

lucasw commented May 2, 2017

Stella debugger expects file names like Boing! (PD) [a1].lst - where does that name come from, it isn't in the test dir?

mv boing26.sym "Boing! (PD) [a1].sym"
mv boing26.lst "Boing! (PD) [a1].lst"

Now it loads them, but there is no cfg file.
Also don't see any difference in dissassembly window- I thought it would use the names for address from the assembly instead of ram_80 etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment