Jump to content
IGNORED

5200 Development Question


kamakazi

Recommended Posts

OK. I have been going over DanB's Hello World Assembly code and trying to understand what is going on step by step. Here is the top portion of that code:

; Atari 5200 "Hello World" sample code
; Written by Daniel Boris (dboris@comcast.net)
;
; Assemble with DASM
;

        processor 6502

; ************ Hardware Adresses ***************************

DMACTL  equ     $D400           ;DMA Control
sDMACTL equ     $07             ;DMA Control Shadow
PMBASE  equ     $D407           ;PM base address
CHBASE  equ     $D409           ;Character set base
GRACTL  equ     $C01D           ;Graphics control
PRIOR   equ     $C01B           ;PM priorities
SIZEP0  equ     $C001           ;Size of player 0
HPOSP0  equ     $C000           ;Horizontal position player 0
COLPM0  equ     $C012           ;Player 0 color
DLISTL  equ     $D402           ;Display list lo
DLISTH  equ     $D403           ;Display list hi
sDLISTL equ     $05             ;Display list lo shadow
sDLISTH equ     $06             ;Display list hi shadow
CHACTL  equ     $D401           ;Character control
NMIEN   equ     $D40E           ;NMI Enable
sCOLPM0 equ      $08            ;Player/missile 0 color shadow
sCOLPM1 equ      $09            ;Player/missile 0 color shadow
sCOLPM2 equ      $0A            ;Player/missile 0 color shadow
sCOLPM3 equ      $0B            ;Player/missile 0 color shadow
sCOLOR0  equ     $0C             ;Color 0 shadow
sCOLOR1  equ     $0D             ;Color 1 shadow
sCOLOR2  equ     $0E             ;Color 2 shadow
sCOLOR3  equ     $0F             ;Color 3 shadow

;*************** Variable ***********************
line equ  $20                   ;Current DLI line
pm0pos equ $21                  ;Current pos of P0

;*************** Start of Code *******************

        org     $4000           ;Start of cartridge area
Start
        sei                     ;Disable interrupts
        cld                     ;Clear decimal mode

;************** Clear zero page and hardware ******

        ldx     #$00
        lda     #$00
crloop1    
        sta     $00,x           ;Clear zero page
        sta     $D400,x         ;Clear ANTIC
        sta     $C000,x         ;Clear GTIA
        sta     $E800,x         ;Clear POKEY
        dex
        bne     crloop1

;************* Clear RAM **************************

        ldy     #$00            ;Clear Ram
        lda     #$02            ;Start at $0200
        sta     $81             
        lda     #$00
        sta     $80
crloop3
        lda     #$00
        sta     ($80),y         ;Store data
        iny                     ;Next byte
        bne     crloop3         ;Branch if not done page
        inc     $81             ;Next page
        lda     $81
        cmp     #$40            ;Check if end of RAM
        bne     crloop3         ;Branch if not

;************* Setup display list *******************

I understand the first portion...labels are being setup to point to memory locations which are important and that can be recalled when needed. Start of code is pointing to the cartridge address at $4000. After that, hardware and page zero are reset to zero. But I don't understand what the "x" is for. Likewise, when clearing RAM I am not understanding what the "y" is for. DEX I understand is decreasing the value of "x" until a 0 is reached, correct. INY is increasing the value of "y" until "y" equals zero, correct? I assume as well with the STA ($80),Y statement that the value of "y" is being placed at address $80. Am I close?

Link to comment
Share on other sites

X and Y are index registers but can be used as general purpose regs in their own right.

 

When you see an instruction operand like $4000,X it means the referenced address is $4000 + whatever is in X.

 

When you see an instruction operand like ($80),Y the brackets mean indirection is taking place. The contents of $80 and $81 contain the base address pointer in low/high byte order then Y is added to form the address that's referenced.

 

Before trying to get too far with 6502 Asm it's a good idea to understand the addressing modes and how the address is calculated. Once you have that sorted it gets much easier, there's not many addressing modes or instructions for that matter, so the whole thing can fall into place pretty quickly.

Link to comment
Share on other sites

  • 7 months later...

Sorry for the delayed response. Been without internet since the end of October. But I did find a neat little program to practice some assembly code on. I made a score system with six digits. It doesn't display anything but while the program is being emulated the developer can track what the memory locations are doing and what the 6502 is doing. It doesn't display anything as I have not found a way for it to display anything. I'm not even sure if it can. It's not much but it's a start.

	.ORG $8000

VARIABLES:

LIVES=$0600
LSCORE=$0602
MSCORE=$0604
RSCORE=$0606
LEVEL=$0608
AREA=$0610

SETUP:
	LDX #3
	STX LIVES
	LDX #1
	STX LEVEL
	STX AREA
RESETSCORE:
	LDX #0
	STX LSCORE
	STX MSCORE
	STX RSCORE

SCORING:
	LDX RSCORE
	CPX #99
	BEQ MSCOREUP
	INX 
	STX RSCORE
	JMP SCORING		
	
MSCOREUP:
	LDX MSCORE
	CMP #99
	BEQ LSCOREUP
	INX
	STX MSCORE
	LDX #0
	STX RSCORE
	JMP SCORING
	
LSCOREUP:
	LDX LSCORE
	CMP #99
	BEQ RESETSCORE
	INX
	STX LSCORE
	LDX #0
	STX MSCORE
	STX RSCORE
	JMP SCORING 

I think I sort of understand the direct memory addressing. I still need to learn the indirect and other ways. I also seriously need to learn the display list. I know I will get it eventually, hopefully.

Link to comment
Share on other sites

I don't know if it is your program or not but just some remarks.. about variable definitions, you have them 2 bytes apart but they took only one byte (maybe on purpose) but AREA variable is at $610 after LEVEL at $608. $ means hexadecimal number so they are 8 bytes apart ($608,$609,$60a,$60b,$60c,$60d,$60e,$60f,$610). Of course it will work too, just pointing it out.

Link to comment
Share on other sites

I wonder i fit really works.

I see two "CMP" instructions but you are using only the X-register and never the A-register (Accumulator).

 

When adding scores (or similar things) which should also be displayed on screen, one can choose to use BCD numbers.

Never have thought about it much, I just use them. Basically you do not need to have a hex->dec conversion routine, as you almost always want to display your scores in decimal :)

 

Maybe that is something to look into to learn more about the 6502. However, I find them only useful for scores and such. I never use them for anything else. So they seem not to be THAT important :)

Edited by Creature XL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...