checkout my comments, learning DASM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MachoDrone

imma gonna accomplish something small with my own code, just to say i did it.

all these comments in the picture are my notes and definitions while reading books by andrew and oscar.
i'll be reading through it frequently until i only read the mnemonics and operands to understand these things better. then i'll move onto using more of them.
i hope this is easier than cq.. i could learn the letters, but i couldn't hardly copy at 5wpm.



Andrew Davie

Quote from: MachoDrone on 12 Sep 2023, 01:24 PMimma gonna accomplish something small with my own code, just to say i did it.

Hard to see the image/contents.
Typically, use the <> code icon when editing, and paste a copy of your code in there... example:

;===============================================================================

    ORG $7FED
    RORG $FFED

ARM_DIRECT_DATA_END

                    jmp InitSystem

                    ds 12, 0                        ; reserve space for CDFJ registers

                    .WORD InitSystem
                    .WORD InitSystem

;===============================================================================
; Display Data
;----------------------------------------
;  4K of RAM shared between the 6507 and ARM.
;
;  NOTE: anything prefixed with _ ends up in main/defines_from_dasm_for_c.h
;        so that the C code will have the same values as the 6507 code
;===============================================================================

    SEG.U DISPLAYDATA
    ORG $0000

_DS_TooARM

_RUN_FUNC          ds 1        ; function to run
_SWCHA              ds 1        ; joystick directions to ARM code
_SWCHB              ds 1        ; console switches to ARM code
_INPT4              ds 1        ; left firebutton state to ARM code
;_INPT5              ds 1        ; right firebutton state to ARM code


MachoDrone

#2
oh, i was just showing the colors since the green sea of comments were so prominent.
you may know this, but there is a photo attachment limit of 0.2MB in your current forum settings, so i just made the pic tiny enough to see colors.

if, you're interested in seeing me type-out a tutorial and comment the hell out of it, here it is.. see how accurate each line is, because the comments vary a little for duplicate mnemonics and operands.
some of the lines are a mile long in case i want to read them.. some of the comments are wrapped-in with a set of instructions.

EDIT: UPDATED CODE HERE ON 9/12/2023 TO KEEP THREAD CLEAN
;TOLEDO

; 160x192 pixels on a TV screen (a little more than 192 rows but the extra rows perhaps could be hidden on some TV sets).
; It can display 128 different colors
; 2 sound tones (2 channels?)
;
; 6507, is only capable of addressing 8K..  1.193 MHz equivalent to 1,193,000 cycles per second
; "The first 4K are used to address the internal peripherals surrounding the 6507 processor like the TIA chip (Television-Interface-Adaptor) composed of around 60 registers, and the RIOT chip (RAM-InputOutput-Timer) with 128 bytes of RAM (Random-Access Memory) and a few registers"
; The other 4K are used to address the cartridge based on ROM (Read Only Memory)
; 6507 processor: has access to 8192 boxes. Each box can contain a value between 0 and 255 (8-bit, or 2 hexadecimal digits)
; The PC (Program Counter) is a register which contains the address.  The position is the address, and the PC contains an address giving the current code location being executed and it is a value between 0 and 65535 (16-bit, or 4 hexadecimal digits)
; It reads the current value of the PC, goes to the indicated box, and reads the instruction. This instruction could be $EA (decimal 234) and he "knows" it means to do nothing (although it does take some time to do nothing, so this can be useful)
; This is known as sequential execution
; knows 56 different instructions with variants
; These instructions do memory load, memory store, arithmetic operations, logic operations, comparisons, transfer between registers, and flow control.
; can also store some 8-bit values known as registers. These registers are A (Accumulator), X, Y, S (Stack pointer), and P (Processor Status).
; processor has six registers. Five of these are 8-bit (A, X, Y, S, and P), and one (PC) is 16-bit.
;
; 6502 / 6507 registers:
;     Accumulator - A: 8-bit register used for arithmetic operations
;                   X:  8-bit INDEX register used for arithmetic operations     ; X & Y are typically used to combine with an address to
;                   Y:  8-bit INDEX register used for arithmetic operations     ; give the ability to index into tables, graphics data, etc
;                   S:  8-bit register used for stack operations
;                   P:  8-bit register used for status flags
;                   PC:  16-bit register used for program counter
;   e.g. When using DEX, DEcrement the value of X (by 1). INX, DEX, INY, DEY, INC address, DEC address... these are all +/-1. Note: There is no equivalent for the accumulator, so you have to manually add or subtract 1
;
;   The P register contains several independent flags:
;
;   Bit 7: The N (Negative) flag is a copy of bit 7 of the result.
;   Bit 6: The V (Overflow) flag is seldom used. It is set when the result of a signed operation is too large a positive number or too small a negative number (excluding the sign bit) to fit in the destination.       
;   Bit 5: - (Unused)
;   Bit 4: The B (Break) flag is set when a BRK instruction has been executed, and an interrupt has been generated to process it., unused on 6507
;           Note: IIRC brk can be triggered manually by executing instruction $00
;   Bit 3: The D (Decimal) flag is used to put the 6502 into BCD (Binary Coded Decimal) mode. Very Useful.
;   Bit 2: The I (Interrupt) flag is used to mask/disable interrupts in the 6502, but is unused in the 6507.
;   Bit 1: The Z (Zero) flag is *set* (1) when the result of an operation is zero. It is *cleared/reset* (0) when the result is non-zero.
;
;   1. Each instruction has its own hexadecimal code.
;   2. Some instructions use one, two, or three bytes.




; tutorial page 8-14, Programming Games for Atari 2600, by Oscar Toledo G.

    PROCESSOR 6502  ; developing for the 6502 / 6507 processor
    INCLUDE vcs.h   ; contains several definitions for the Atari 2600

    ORG $F000  ; --- the following instructions start at the hexadecimal address $F000, You could also use decimal by not using any prefixes, so it would read ORG 61440
; Note: PROCESSOR, INCLUDE, and ORG are all directives to the assembler, not processor instructions.

START:       ; label used by the reset vector -- ALWAYS USE COLON for ease of searching labels in your code
    SEI      ; Optional. There is no INT pin on the 6507. SEt internal Interrupt flag bit, commands the processor to not accept external interrupts via its INT pin.
    CLD      ; CLear Decimal mode flag bit, This way the processor understands that every ADC/SBC instruction will operate in normal binary mode
    LDX #$FF ; LoaD the register X with the value $FF; notice the symbol # in the source code, value is an "immediate", used directly by processor
    TXS      ; The value in X is copied into the S register by the TXS instruction
    LDA #$00 ;LoaD the register A or accumulator with the value $00 in order to start the Memory 'CLEAR:' loop

CLEAR:  ; Memory 'CLEAR:' loop
    STA 0,X   ; STore the value in the Accumulator, saves the current value of A (zero) onto the memory address 0+X (where X is the current value of X register)
    DEX       ; DEcrement the value of X (by 1). INX, DEX, INY, DEY, INC address, DEC address... these are all +/-1. Note: There is no equivalent for the accumulator, so you have to manually add or subtract 1
    BNE CLEAR ; Branch if Not Equal, branches to the label 'CLEAR' if the value of X is not equal to zero
    ; All this results in clearing to zero the whole RAM memory located at $0080-$00ff and video state located at $0000-$007f,
    ; and getting us to a well-defined startup state

SHOW_FRAME:    ; marks where the program will loop indefinitely, creating the video frame shown on the screen. ***IDE DOES NOT COLOR THIS LABEL PURPLE WHEN THE UNDERSCORE IS USED***
    LDA #$88   ; LoaD the TIA's COLUBK register with a value of $88, meaning a deep sea blue color (only on NTSC TV sets)
    STA COLUBK ; BacKground COLorstore, load the value in the Accumulator into the COLUBK register, sets the background color

; PAGE 11 (pg.26 in PDF) has a TIA timing diagram, which shows the horizontal and vertical blanking periods, and the visible area of the screen
; The visible area of the screen is 192 pixels wide by 160 pixels high, and is divided into 192 lines of 160 pixels each
; The horizontal blanking period is 68 pixels wide, and the vertical blanking period is 3 lines high

    STA WSYNC ; Wait for SYNChronization, waits for a scanline to start, the horizontal blanking period starts
    LDA #2    ; LoaD the Accumulator with the value 2, which is the number of cycles to wait
    STA VSYNC ; Vertical SYNChronization, waits until the vertical blanking period starts
    STA WSYNC     ; Wait for SYNChronization, waits until the horizontal blanking period starts
    STA WSYNC     ; waits for three scanlines by writing three times to the register WSYNC. The WSYNC register is a strobe-only register.
    STA WSYNC     ; This means it doesn't matter what value you write to it; as soon as you perform a write it halts the 6507 until the
                  ; start of the next scanline. This is one way to synchronize your code with the display
    LDA #0    ; LoaD the Accumulator with the value 0, which is the number of cycles to wait
    STA VSYNC ; Once the three scanlines are complete, it stops the vertical retrace by loading zero into the register VSYNC

    LDA #36       ; Now it counts 36 scanlines using the X register...
TOP:
    STA WSYNC     ; Note how it writes into WSYNC,...
    DEX           ; decrements the X register,...
    BNE TOP       ; and repeats the loop until X becomes zero.

    LDA #0  ; LoaD the Accumulator with the value 0, which is the number of cycles to wait
    STA VBLANK ; Once the 36 scanlines are complete, it stops the vertical retrace by loading zero into the register VBLANK
    LDX #192    ; LoaD the X register with the value 192, which is the number of cycles to wait
VISIBLE:
    STA WSYNC   ; Wait for SYNChronization, waits for a scanline to start, the horizontal blanking period starts
    DEX         ; DEcrement the value of X (by 1)
    BNE VISIBLE ; Branch if Not Equal, branches to the label 'VISIBLE' if the value of X is not equal to zero
; We have reached the visible portion. Typically only 192 scanlines are visible out of 262

    LDA #2          ; After the visible portion of the screen, we write 2... (LoaD the Accumulator)
    STA VBLANK      ; to the VBLANK register. This turns off the display,...
    LDX #30         ;  and we count 30 rows for the bottom border...  (LoaD the X register with the value 30)
BOTTOM:
    STA WSYNC       ; Once this is complete, it jumps again to SHOW_FRAME...
    DEX             ; to repeat the cycle of the display...
    BNE BOTTOM      ; Notice the VBLANK register remains set until being disabled again just before the VISIBLE label.

    JMP SHOW_FRAME ; JuMP to the label 'SHOW_FRAME', which is the start of the program loop

; We need a further step before assembling this program: Giving an indication of the starting address of execution.
; Why is this? Because on reset, the 6502 processor reads the contents of two bytes starting at the address $FFFC
; to get the starting execution address, and the address $FFFE should contain the address for an interrupt
; or BRK handler (not used, but we use the same value).

    ORG $FFFC   ; The directive .word tells the assembler to put the 16-bit value as two bytes,
    .word START ; first the low-byte (bits 0-7), and then the high-byte (bits 8-15). This means
    .word START ; in binary it will appear as: $FC $FF

; Page 14 (pg.29 PDF)

Andrew Davie

#3
Quote from: MachoDrone on 12 Sep 2023, 01:42 PMoh, i was just showing the colors since the green sea of comments were so prominent.
you may know this, but there is a photo attachment limit of 0.2MB in your current forum settings, so i just made the pic tiny enough to see colors.

Now fixed.

;    The position (or "address") of this box is known as PC (Program Counter) and it is a value between 0 and 65535 (16-bit, or 4 hexadecimal digits)

Almost.  The PC is a register which contains the address.  So the position is not called the program counter;  the position is the address, and the program counter contains an address giving the current code location being executed.

;                  X:  8-bit register used for arithmetic operations
;                  Y:  8-bit register used for arithmetic operations

X and Y are known as index registers and they have only increment and decrement (by one) arithmetic capability.  Typically they are used to combine with an address to give the ability to index into tables, graphics data, etc.

;  Bit 4: The B (Break) flag is set when a BRK instruction has been executed, and an interrupt has been generated to process it.
;  Bit 3: The D (Decimal) flag is used to put the 6502 into BCD (Binary Coded Decimal) mode. Very Useful.
;  Bit 2: The I (Interrupt) flag is used to mask/disable interrupts in the 6502, but is unused in the 6507.

The '2600 does not generate break or interrupts - although IIRC brk can be triggered manually by executing instruction $00.

    ORG $F000  ; --- the following instructions start at the hexadecimal address $F000, which is the reset vector for the 6507 processor

No. Terminology is important here.  The vectors are the group of words at the end of the ROM (non-maskable interrupt vector, break vector, reset vector).  Those words point to anywhere in memory and the 6507 will load the address from those vectors when the associated event happens. So the reset vector can point to anywhere in your code, wherever you happen to put the startup code you want to run on reset.

START:      ; label used by the reset vector -- ALWAYS USE COLON for ease of searching labels in your code

There are some style differences bewteen developers here. One is the use of colon. I hate it, and do not use it at all.  Many use it.  You do not need to have a label on its own line; you can follow it by a space and a mnemonic (e.g., "START SEI"), And while we're at it, ALL UPPERCASE MNEMONICS/LABELS is like shouting. Hard to read, and unnecessary.  So many of the experienced developers will use lowercase - but again, a style thing. I'm more likely to help you with your code if it's lowercase ;)

On the subject of "finding" the definition of a label, in Atari Developer Studio, I just ctrl-click on the label usage, and it jumps right to the definition for me. Using this IDE, at least, there's absolutely no need to put the : at the end of the definition line.

    SEI      ; SEt internal Interrupt flag bit, commands the processor to not accept external interrupts via its INT pin (no INT pin on 6507)

The above is standard, and good practice -- but the '2600 does not actually generate non-maskable interrupts so the SEI is superfluous.

    DEX      ; DEcrement the value of X (by 1?)

Yes. INX, DEX, INY, DEY, INC address, DEC address... these are all +/-1
There is no equivalent for the accumulator, so you have to manually add or subtract 1.

MachoDrone

thanks so much for reviewing my comments.
some were copied and pasted from the book i was following and some were automatically added by Atari Dev Studio or CoPilot.
..whenever they were automatically generated by GitHub CoPilot they were terrible. and i was using the tab so frequently to align things, it would think i'm accepting the text every time. CoPilot also rarely predicted any code correctly.
I also had a hard time keeping some of the words lowercase and gave-up.. i kept them uppercase as it would be a bear to continuously fuss-around with.

Here are the results of what should be a simple blue screen, per nanochess' book and chapter 1.4 tutorial.
first in the video is Stella, 2nd to play is Gopher2600.

I triple checked the code to the book. Is there a bug in the book?
https://youtube.com/shorts/pxOkcm1-gR4
@nanochess @JetSetIlly
Quote from: JetSetIlly on 09 Sep 2023, 04:09 AM...

Andrew Davie

Use "Ctrl-L" in Stella, or "F7" in Gopher to bring up an overlay giving you some stats/info on the frame being generated. In particular, it looks to me like you're not generating a 262 scanline screen there.  Of the two, I would trust Gopher in terms of showing you what it will actually look like on a TV.

An option is to share all your source code - usually people in forums will be very helpful in diagnosing.

MachoDrone

#6
it's the same code that's at my 2nd post in this thread, but i've corrected the comments.
Programming Games for the Atari 2600 by Oscar Toledo G.
My deep gratitude goes to Michael Hayes and Andrew Davie for
proofreading this book. Also Thomas Jentzsch...
.

i'm using the first tutorial at section 1.4 00 it should just be a blue screen.

i could pause Gopher2600 and only see two scanline counts of 169 and 313, absolute consistency with each pause.. those were the only 2 numbers to ever show during a pause. The rolling or flickering blue bars would show at a different location each time i paused.

i found a list of key strokes for Stella, it was Alt+L for frame status.
pausing Stella would make the frame stats disappear.
the top half of the screen is rapidly flickering black to blue everytime it's launched, just like in the video.

i find this intersting and first thoughts was i'm the problem, but i can't find any problems with how the code looks compared to the book.

if you find the solution with an error in the code, like if code needs a MINOR edit, maybe not tell me what to do, but verify it's in the code and i'll try to look at the code and figure it out.

but if there is missing code to solve it, i prolly will fail, so let me know that, too. lol


thanks!

EDIT: i slowed-down stella to 10% and found screen capturing would show the upper half of the screen is blue at 172 and all black at 310


Andrew Davie

Quote from: MachoDrone on 12 Sep 2023, 01:42 PM    LDA #36       ; Now it counts 36 scanlines using the X register...

In this line you are loading 36 into the accumulator, when it should be LDX into the x register.
Because you have not correctly initialised X, your scanline count depends on whatever X happens to be.
Almost certainly your major problem/bug right there.

Andrew Davie

#8
Quote from: MachoDrone on 12 Sep 2023, 01:42 PM    LDA #2    ; LoaD the Accumulator with the value 2, which is the number of cycles to wait
    STA VSYNC ; Vertical SYNChronization, waits until the vertical blanking period starts

    LDA #0    ; LoaD the Accumulator with the value 0, which is the number of cycles to wait
    STA VSYNC ; Once the three scanlines are complete, it stops the vertical retrace by loading zero into the register VSYNC


The coments are incorrect in the above two lines. The value loaded into the accumulator is not a count of cycles.  The VSYNC register is a control register which uses particular bits to do various stuff. When you store 0 to that register you clear all the bits. When you store 2 to that register, you are actually setting bit #1. (bit0=1, bit1=2, bit2=4, bit3=8.... bit7=128).  So, what does bit 1 of VSYNC do?

As it happens, *only* bit 1 in VSYNC is actually used - and it controls the generation of a VSYNC signal. Setting bit1 (also called D1) to 1 will enable VSYNC.  Setting to 0 disables.  Some '2600 registers use bit values like this, and some are simply strobe registers (WSYNC is a strobe register) which simply don't care what you write to them - just writing anything causes them to "trigger".

MachoDrone

omg. of course the book is right and the comment i created was right.
i compared the book and my code multiple times and missed it.  :-[
now, the blue screen appears, of course

your comment corrections and explanations are excellent. thanks, so much. i'll be re-reading these comments as my notes as i re-read this section of the book and see if there are any other comments either i or CoPilot messed-up.

i only had copilot so i could see if it's worth a damn on DASM code or comments. it's disappointing and probably not worth the struggle.. it's put you to work probably has hard as me. i appreciate your time.