Tuesday, January 21, 2025

Fourth Posting Lab2: Math Lab

Lab 2 is named Bouncing Graphic, 

Follow these steps:

  1. You will be assigned to a Zoom breakout group. Within the group, select someone to be the initial “Driver” - the person who will be typing.
  2. Decide on how you're going to share the final code between members of your group. This might be as simple as pasting it into the Zoom chat (Caution!), or you could use a pastebin, e-mail attachment, Git repository, or any other scheme that everyone agrees upon.
  3. Have the Driver share their screen with the group.
  4. Collaborate with the Driver using audio and/or video. In Pair or Mob Programming, most of the coding suggestions come from those observing the Driver, not the Driver themselves.
  5. It can be a good idea to switch the driver periodically as you see fit.
  6. Follow Lab instructions:
Test the given code by pressing the Assemble button, then the Run button. You can adjust the speed slider as needed. If the there are any errors assembling (compiling) the code, they will appear in the message area at the bottom of the page. Make sure the code is running correctly and that you understands how it works. Don't be afraid to experiment!


Bouncing Graphic

4. Select a starting location for the graphic where X and Y have different values.

5. Select an X increment that is -1 or +1, and a Y increment that is -1 or +1. You can choose to use either a signed byte or some other representation to hold these values.

6. Successively move the graphic by adding the X and Y increments to the graphic's X and Y position.

7. Make the graphic bounce when it hits the edge of the bitmapped screen, both vertically (when it hits the top/bottom) and horizontally (when it hits the left/right edge).


GIVEN CODE:

;
; draw-image-subroutine.6502
;
; This is a routine that can place an arbitrary 
; rectangular image on to the screen at given
; coordinates.
;
; Chris Tyler 2024-09-17
; Licensed under GPLv2+
;

;
; The subroutine is below starting at the 
; label "DRAW:"
;

; Test code for our subroutine
; Moves an image diagonally across the screen

; Zero-page variables
define XPOS $20
define YPOS $21


START:

; Set up the width and height elements of the data structure
  LDA #$05
  STA $12       ; IMAGE WIDTH
  STA $13       ; IMAGE HEIGHT

; Set initial position X=Y=0
  LDA #$00
  STA XPOS
  STA YPOS

; Main loop for diagonal animation
MAINLOOP:

  ; Set pointer to the image
  ; Use G_O or G_X as desired
  ; The syntax #<LABEL returns the low byte of LABEL
  ; The syntax #>LABEL returns the high byte of LABEL

  LDA #<G_O
  STA $10
  LDA #>G_O
  STA $11

  ; Place the image on the screen
  LDA #$10  ; Address in zeropage of the data structure
  LDX XPOS  ; X position
  LDY YPOS  ; Y position
  JSR DRAW  ; Call the subroutine

  ; Delay to show the image
  LDY #$00
  LDX #$50
DELAY:
  DEY
  BNE DELAY
  DEX
  BNE DELAY

  ; Set pointer to the blank graphic
  LDA #<G_BLANK
  STA $10
  LDA #>G_BLANK
  STA $11

  ; Draw the blank graphic to clear the old image
  LDA #$10 ; LOCATION OF DATA STRUCTURE
  LDX XPOS
  LDY YPOS
  JSR DRAW

  ; Increment the position
  INC XPOS
  INC YPOS

  ; Continue for 29 frames of animation
  LDA #28
  CMP XPOS
  BNE MAINLOOP

  ; Repeat infinitely
  JMP START

; ==========================================
;
; DRAW :: Subroutine to draw an image on 
;         the bitmapped display
;
; Entry conditions:
;    A - location in zero page of: 
;        a pointer to the image (2 bytes)
;        followed by the image width (1 byte)
;        followed by the image height (1 byte)
;    X - horizontal location to put the image
;    Y - vertical location to put the image
;
; Exit conditions:
;    All registers are undefined
;
; Zero-page memory locations
define IMGPTR    $A0
define IMGPTRH   $A1
define IMGWIDTH  $A2
define IMGHEIGHT $A3
define SCRPTR    $A4
define SCRPTRH   $A5
define SCRX      $A6
define SCRY      $A7

DRAW:
  ; SAVE THE X AND Y REG VALUES
  STY SCRY
  STX SCRX

  ; GET THE DATA STRUCTURE
  TAY
  LDA $0000,Y
  STA IMGPTR
  LDA $0001,Y
  STA IMGPTRH
  LDA $0002,Y
  STA IMGWIDTH
  LDA $0003,Y
  STA IMGHEIGHT

  ; CALCULATE THE START OF THE IMAGE ON
  ; SCREEN AND PLACE IN SCRPTRH
  ;
  ; THIS IS $0200 (START OF SCREEN) +
  ; SCRX + SCRY * 32
  ; 
  ; WE'LL DO THE MULTIPLICATION FIRST
  ; START BY PLACING SCRY INTO SCRPTR
  LDA #$00
  STA SCRPTRH
  LDA SCRY
  STA SCRPTR
  ; NOW DO 5 LEFT SHIFTS TO MULTIPLY BY 32
  LDY #$05     ; NUMBER OF SHIFTS
MULT:
  ASL SCRPTR   ; PERFORM 16-BIT LEFT SHIFT
  ROL SCRPTRH
  DEY
  BNE MULT

  ; NOW ADD THE X VALUE
  LDA SCRX
  CLC
  ADC SCRPTR
  STA SCRPTR
  LDA #$00
  ADC SCRPTRH
  STA SCRPTRH

  ; NOW ADD THE SCREEN BASE ADDRESS OF $0200
  ; SINCE THE LOW BYTE IS $00 WE CAN IGNORE IT
  LDA #$02
  CLC
  ADC SCRPTRH
  STA SCRPTRH
  ; NOTE WE COULD HAVE DONE TWO: INC SCRPTRH

  ; NOW WE HAVE A POINTER TO THE IMAGE IN MEM
  ; COPY A ROW OF IMAGE DATA
COPYROW:
  LDY #$00
ROWLOOP:
  LDA (IMGPTR),Y
  STA (SCRPTR),Y
  INY
  CPY IMGWIDTH
  BNE ROWLOOP

  ; NOW WE NEED TO ADVANCE TO THE NEXT ROW
  ; ADD IMGWIDTH TO THE IMGPTR
  LDA IMGWIDTH
  CLC
  ADC IMGPTR
  STA IMGPTR
  LDA #$00
  ADC IMGPTRH
  STA IMGPTRH
 
  ; ADD 32 TO THE SCRPTR
  LDA #32
  CLC
  ADC SCRPTR
  STA SCRPTR
  LDA #$00
  ADC SCRPTRH
  STA SCRPTRH

  ; DECREMENT THE LINE COUNT AND SEE IF WE'RE
  ; DONE
  DEC IMGHEIGHT
  BNE COPYROW

  RTS

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

; 5x5 pixel images

; Image of a blue "O" on black background
G_O:
DCB $00,$0e,$0e,$0e,$00
DCB $0e,$00,$00,$00,$0e
DCB $0e,$00,$00,$00,$0e
DCB $0e,$00,$00,$00,$0e
DCB $00,$0e,$0e,$0e,$00

; Image of a yellow "X" on a black background
G_X:
DCB $07,$00,$00,$00,$07
DCB $00,$07,$00,$07,$00
DCB $00,$00,$07,$00,$00
DCB $00,$07,$00,$07,$00
DCB $07,$00,$00,$00,$07

; Image of a black square
G_BLANK:
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
Output:

Output looks like a blue ball is moving left top (where x is 0 and y is 0) to right
bottom end( where max x and max y)

Before we proceed with the code lets break down how the given code is structured:
If you look at the bottom of this code there is something that is important
That we use in a lot of parts in this whole code:

; Image of a blue "O" on black background
G_O:
DCB $00,$0e,$0e,$0e,$00
DCB $0e,$00,$00,$00,$0e
DCB $0e,$00,$00,$00,$0e
DCB $0e,$00,$00,$00,$0e
DCB $00,$0e,$0e,$0e,$00

; Image of a yellow "X" on a black background
G_X:
DCB $07,$00,$00,$00,$07
DCB $00,$07,$00,$07,$00
DCB $00,$00,$07,$00,$00
DCB $00,$07,$00,$07,$00
DCB $07,$00,$00,$00,$07

; Image of a black square
G_BLANK:
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
So now we know where are all the G_XXX is coming from: Then from the start after the comment about description of this whole code we see: ; Zero-page variables define XPOS $20 define YPOS $21 This is to store zero page (addresses $00-$FF) variables that might change frequently
Then now we see:

START:

; Set up the width and height elements of the data structure
  LDA #$05
  STA $12       ; IMAGE WIDTH
  STA $13       ; IMAGE HEIGHT
; Set initial position X=Y=0
  LDA #$00
  STA XPOS
  STA YPOS

The START label marks the beginning of our program's excution.
Then we go for making(loading) dimension of a image and marking the starting position
; Main loop for diagonal animation
MAINLOOP:

  ; Set pointer to the image
  ; Use G_O or G_X as desired
  ; The syntax #<LABEL returns the low byte of LABEL
  ; The syntax #>LABEL returns the high byte of LABEL

  LDA #<G_O
  STA $10
  LDA #>G_O
  STA $11

Now the Main loop started and we are setting up image pointer and start to animate
the images.

In here we need to tell our drawing routine which graphic to use in here we are using
BLUE(G_O) as well as load them in low byte and high byte ($10 and $11) so contains
full 16-bit pointer to the graphic data for G_O
 ; Place the image on the screen
  LDA #$10  ; Address in zeropage of the data structure
  LDX XPOS  ; X position
  LDY YPOS  ; Y position
  JSR DRAW  ; Call the subroutine

Then we place image on the screen:
$LDA#$10 loads the number $10 into the accumulator since all the information is
stored in $10

And loads X position and Y position from the saved zero page vars on the top of this
code

And JSR (Jump to Subroutine) saves the return address on the stack, the DRAW
routine will use these values to copy the image data to the correct places.
 ; Delay to show the image
  LDY #$00
  LDX #$50
DELAY:
  DEY
  BNE DELAY
  DEX
  BNE DELAY

This block of a code gives some time to code to execute on screen for a moment to
make it more 'visible'
This sets Y to 0 then loads X to $50(80), where it sets delay's timespan.
DELAY: starts the delay

and we see DEY (Decrement Y) and BNE where it makes lasting till Y gets 0.
Then when Y becomes 0 the code decrements X with DEX and again Branch not Equal to Zero
; Set pointer to the blank graphic
  LDA #<G_BLANK
  STA $10
  LDA #>G_BLANK
  STA $11

  ; Draw the blank graphic to clear the old image
  LDA #$10 ; LOCATION OF DATA STRUCTURE
  LDX XPOS
  LDY YPOS
  JSR DRAW

this block of code shows image for a moment and clears previous image to show its
like having a movement. Simply shows graphic and shows blank graphic. and with JSR
we can see that it copies blank graphic to the screen and "removing" the previous
image

 ; Increment the position
  INC XPOS
  INC YPOS

  ; Continue for 29 frames of animation
  LDA #28
  CMP XPOS
  BNE MAINLOOP

  ; Repeat infinitely
  JMP START

moving the image diagonally, we increment both X and Y positions.
And runs through 29frames then restarts after that.
LDA loads 28, and CMP XPOS will compare this value with current Xpos and if they
are not equal then branches back to MAINLOOP
And the rest of the codes follows as the given comments, for drawing the image.


; ==========================================
;
; DRAW :: Subroutine to draw an image on 
;         the bitmapped display
;
; Entry conditions:
;    A - location in zero page of: 
;        a pointer to the image (2 bytes)
;        followed by the image width (1 byte)
;        followed by the image height (1 byte)
;    X - horizontal location to put the image
;    Y - vertical location to put the image
;
; Exit conditions:
;    All registers are undefined
;
; Zero-page memory locations
define IMGPTR    $A0
define IMGPTRH   $A1
define IMGWIDTH  $A2
define IMGHEIGHT $A3
define SCRPTR    $A4
define SCRPTRH   $A5
define SCRX      $A6
define SCRY      $A7

DRAW:
  ; SAVE THE X AND Y REG VALUES
  STY SCRY
  STX SCRX

  ; GET THE DATA STRUCTURE
  TAY
  LDA $0000,Y
  STA IMGPTR
  LDA $0001,Y
  STA IMGPTRH
  LDA $0002,Y
  STA IMGWIDTH
  LDA $0003,Y
  STA IMGHEIGHT

  ; CALCULATE THE START OF THE IMAGE ON
  ; SCREEN AND PLACE IN SCRPTRH
  ;
  ; THIS IS $0200 (START OF SCREEN) +
  ; SCRX + SCRY * 32
  ; 
  ; WE'LL DO THE MULTIPLICATION FIRST
  ; START BY PLACING SCRY INTO SCRPTR
  LDA #$00
  STA SCRPTRH
  LDA SCRY
  STA SCRPTR
  ; NOW DO 5 LEFT SHIFTS TO MULTIPLY BY 32
  LDY #$05     ; NUMBER OF SHIFTS
MULT:
  ASL SCRPTR   ; PERFORM 16-BIT LEFT SHIFT
  ROL SCRPTRH
  DEY
  BNE MULT

  ; NOW ADD THE X VALUE
  LDA SCRX
  CLC
  ADC SCRPTR
  STA SCRPTR
  LDA #$00
  ADC SCRPTRH
  STA SCRPTRH

  ; NOW ADD THE SCREEN BASE ADDRESS OF $0200
  ; SINCE THE LOW BYTE IS $00 WE CAN IGNORE IT
  LDA #$02
  CLC
  ADC SCRPTRH
  STA SCRPTRH
  ; NOTE WE COULD HAVE DONE TWO: INC SCRPTRH

  ; NOW WE HAVE A POINTER TO THE IMAGE IN MEM
  ; COPY A ROW OF IMAGE DATA
COPYROW:
  LDY #$00
ROWLOOP:
  LDA (IMGPTR),Y
  STA (SCRPTR),Y
  INY
  CPY IMGWIDTH
  BNE ROWLOOP

  ; NOW WE NEED TO ADVANCE TO THE NEXT ROW
  ; ADD IMGWIDTH TO THE IMGPTR
  LDA IMGWIDTH
  CLC
  ADC IMGPTR
  STA IMGPTR
  LDA #$00
  ADC IMGPTRH
  STA IMGPTRH
 
  ; ADD 32 TO THE SCRPTR
  LDA #32
  CLC
  ADC SCRPTR
  STA SCRPTR
  LDA #$00
  ADC SCRPTRH
  STA SCRPTRH

  ; DECREMENT THE LINE COUNT AND SEE IF WE'RE
  ; DONE
  DEC IMGHEIGHT
  BNE COPYROW

  RTS

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

; 5x5 pixel images

; Image of a blue "O" on black background
G_O:
DCB $00,$0e,$0e,$0e,$00
DCB $0e,$00,$00,$00,$0e
DCB $0e,$00,$00,$00,$0e
DCB $0e,$00,$00,$00,$0e
DCB $00,$0e,$0e,$0e,$00

; Image of a yellow "X" on a black background
G_X:
DCB $07,$00,$00,$00,$07
DCB $00,$07,$00,$07,$00
DCB $00,$00,$07,$00,$00
DCB $00,$07,$00,$07,$00
DCB $07,$00,$00,$00,$07

; Image of a black square
G_BLANK:
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
DCB $00,$00,$00,$00,$00
Now Lets try the instructions on lab:

4. Select a starting location for the graphic where X and Y have different values.

I believe in order to achieve this we can adjust the zero page vars with initializing with different values

; Set initial position X=Y=0 LDA #$00 STA XPOS STA YPOS instead of this lets try ; Set initial position X=Y=0 LDA #$10 STA XPOS LDA #$05 STA YPOS Then as expected we can see that starting location gets changed
#$10 : XPOS = 16 horizontal starting position is 16 pixels from the left
#$05 setting YPOS to 5(dec)5 rows down starting point
So it is true that we are seeing the blue circle a bit right then 0,0 position and going right bottom movement.

5.Select an X increment that is -1 or +1, and a Y increment that is -1 or +1. You can choose to use either a signed byte or some other representation to hold these values.


We can simply achieve this by adjusting

INC XPOS (to DEC XPOS)
DEC YPOS (to INC YPOS)

and we can see that now it moves to different direction and including previous question even different starting position.





6. Successively move the graphic by adding the X and Y increments to the graphic's X and Y position.

7. Make the graphic bounce when it hits the edge of the bitmapped screen, both vertically (when it hits the top/bottom) and horizontally (when it hits the left/right edge).

In order to achieve these we are adding two new variables for directional flag

define XDIR $24
define YDIR $25

And initialize them. For me i did Moving right and up (X, Y)

  LDA #$00
  STA XDIR      ; 0 means move right
  LDA #$01
  STA YDIR      ; 1 means move up

And after setting the pointer to blank graphics we are going to add bouncing logic code.

  ; Check horizontal boundaries

  LDA XPOS

  CMP #$00

  BEQ SET_X_INC       

  CMP #$1B            ; 0x1B = 27 decimal.

  BEQ SET_X_DEC     


-Loads the current Xposition
-Compares the X position with 0
-Compares if the XPOS is equal to right edge


  ; Check vertical boundaries

  LDA YPOS

  CMP #$00

  BEQ SET_Y_INC    

  CMP #$1B

  BEQ SET_Y_DEC      


- Loads ccurrent Y position
- Compares YPOS with 0
- compares YPOS with bottom edge




; Update Positions Based on Direction Flags

UPDATE_POS:

  ; Update X position:

  LDA XDIR

  BEQ X_MOVE_INC  

  DEC XPOS           

  JMP UPDATE_Y


- Loads directional flag
- if XDIR equals 0 then we want to move in positive direction, so jump to the label X_MOVE_INC
-if XDIR is not zero(when its 1) then excutes the DEC XPOS (moves left)



X_MOVE_INC:

  INC XPOS

- increment the X position by one, moving the image to the right


UPDATE_Y:

  LDA YDIR

  BEQ Y_MOVE_INC     

  DEC YPOS       

  JMP CONTINUE_LOOP

- Loads Vertical directional flag
- if YDIR equals 0, then move in the positive direction(down), so branch to Y_MOVE_INC
- if YDIR is not zero, decrement YPOS
- After updating YPOS, jump to the continuation of the main loop


Y_MOVE_INC:

  INC YPOS

- Increments the Y position by one, moving the image down

CONTINUE_LOOP:

  JMP MAINLOOP

- Restarting the main loop

SET_X_INC:

  LDA #$00      

  STA XDIR

  JMP UPDATE_POS


SET_X_DEC:

  LDA #$01      

  STA XDIR

  JMP UPDATE_POS

- Setting up the horizontal directional flag

SET_Y_INC:

  LDA #$00

  STA YDIR

  JMP UPDATE_POS


SET_Y_DEC:

  LDA #$01

  STA YDIR

  JMP UPDATE_POS

- setting up the vertical directional flag













Complete code below:

;

; draw-image-subroutine.6502

;;

; draw-image-subroutine.6502

;

; This is a routine that can place an arbitrary 

; rectangular image on to the screen at given

; coordinates.

;

; Chris Tyler 2024-09-17

; Licensed under GPLv2+

;


;

; The subroutine is below starting at the 

; label "DRAW:"

;


; Test code for our subroutine

; Moves an image diagonally across the screen


; Zero-page variables

define XPOS $20

define YPOS $21

; Direction flags (0 = moving in the positive direction; 1 = moving negative)

define XDIR   $24    ; X direction flag

define YDIR   $25    ; Y direction flag


START:


; Set up the width and height elements of the data structure

  LDA #$05

  STA $12       ; IMAGE WIDTH

  STA $13       ; IMAGE HEIGHT


  ; Set initial position

  LDA #$10      ; starting X = 16 (decimal)

  STA XPOS

  LDA #$10      ; starting Y = 16 (decimal)

  STA YPOS

 ; Initialize the direction flags.

  ; For example, start with X moving to the right (flag = 0) and

  ; Y moving upward (flag = 1 to mean “decrease”).

  LDA #$00

  STA XDIR      ; 0 means INC (move right)

  LDA #$01

  STA YDIR      ; 1 means DEC (move up)


; Main loop for diagonal animation

MAINLOOP:


  ; Set pointer to the image

  ; Use G_O or G_X as desired

  ; The syntax #<LABEL returns the low byte of LABEL

  ; The syntax #>LABEL returns the high byte of LABEL


  LDA #<G_O

  STA $10

  LDA #>G_O

  STA $11


  ; Place the image on the screen

  LDA #$10  ; Address in zeropage of the data structure

  LDX XPOS  ; X position

  LDY YPOS  ; Y position

  JSR DRAW  ; Call the subroutine


  ; Delay to show the image

  LDY #$00

  LDX #$50

DELAY:

  DEY

  BNE DELAY

  DEX

  BNE DELAY


  ; Set pointer to the blank graphic

  LDA #<G_BLANK

  STA $10

  LDA #>G_BLANK

  STA $11


  ; Draw the blank graphic to clear the old image

  LDA #$10 ; LOCATION OF DATA STRUCTURE

  LDX XPOS

  LDY YPOS

  JSR DRAW


  LDA XPOS

  CMP #$00

  BEQ SET_X_INC      

  CMP #$1B            

  BEQ SET_X_DEC      


  LDA YPOS

  CMP #$00

  BEQ SET_Y_INC      

  CMP #$1B

  BEQ SET_Y_DEC      


UPDATE_POS:

  LDA XDIR

  BEQ X_MOVE_INC    

  DEC XPOS          

  JMP UPDATE_Y


X_MOVE_INC:

  INC XPOS


UPDATE_Y:

  LDA YDIR

  BEQ Y_MOVE_INC     

  DEC YPOS         

  JMP CONTINUE_LOOP


Y_MOVE_INC:

  INC YPOS


CONTINUE_LOOP:

  JMP MAINLOOP


SET_X_INC:

  LDA #$00        

  STA XDIR

  JMP UPDATE_POS


SET_X_DEC:

  LDA #$01       

  STA XDIR

  JMP UPDATE_POS


SET_Y_INC:

  LDA #$00

  STA YDIR

  JMP UPDATE_POS


SET_Y_DEC:

  LDA #$01

  STA YDIR

  JMP UPDATE_POS

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

;

; DRAW :: Subroutine to draw an image on 

;         the bitmapped display

;

; Entry conditions:

;    A - location in zero page of: 

;        a pointer to the image (2 bytes)

;        followed by the image width (1 byte)

;        followed by the image height (1 byte)

;    X - horizontal location to put the image

;    Y - vertical location to put the image

;

; Exit conditions:

;    All registers are undefined

;

; Zero-page memory locations

define IMGPTR    $A0

define IMGPTRH   $A1

define IMGWIDTH  $A2

define IMGHEIGHT $A3

define SCRPTR    $A4

define SCRPTRH   $A5

define SCRX      $A6

define SCRY      $A7


DRAW:

  ; SAVE THE X AND Y REG VALUES

  STY SCRY

  STX SCRX


  ; GET THE DATA STRUCTURE

  TAY

  LDA $0000,Y

  STA IMGPTR

  LDA $0001,Y

  STA IMGPTRH

  LDA $0002,Y

  STA IMGWIDTH

  LDA $0003,Y

  STA IMGHEIGHT


  ; CALCULATE THE START OF THE IMAGE ON

  ; SCREEN AND PLACE IN SCRPTRH

  ;

  ; THIS IS $0200 (START OF SCREEN) +

  ; SCRX + SCRY * 32

  ; 

  ; WE'LL DO THE MULTIPLICATION FIRST

  ; START BY PLACING SCRY INTO SCRPTR

  LDA #$00

  STA SCRPTRH

  LDA SCRY

  STA SCRPTR

  ; NOW DO 5 LEFT SHIFTS TO MULTIPLY BY 32

  LDY #$05     ; NUMBER OF SHIFTS

MULT:

  ASL SCRPTR   ; PERFORM 16-BIT LEFT SHIFT

  ROL SCRPTRH

  DEY

  BNE MULT


  ; NOW ADD THE X VALUE

  LDA SCRX

  CLC

  ADC SCRPTR

  STA SCRPTR

  LDA #$00

  ADC SCRPTRH

  STA SCRPTRH


  ; NOW ADD THE SCREEN BASE ADDRESS OF $0200

  ; SINCE THE LOW BYTE IS $00 WE CAN IGNORE IT

  LDA #$02

  CLC

  ADC SCRPTRH

  STA SCRPTRH

  ; NOTE WE COULD HAVE DONE TWO: INC SCRPTRH


  ; NOW WE HAVE A POINTER TO THE IMAGE IN MEM

  ; COPY A ROW OF IMAGE DATA

COPYROW:

  LDY #$00

ROWLOOP:

  LDA (IMGPTR),Y

  STA (SCRPTR),Y

  INY

  CPY IMGWIDTH

  BNE ROWLOOP


  ; NOW WE NEED TO ADVANCE TO THE NEXT ROW

  ; ADD IMGWIDTH TO THE IMGPTR

  LDA IMGWIDTH

  CLC

  ADC IMGPTR

  STA IMGPTR

  LDA #$00

  ADC IMGPTRH

  STA IMGPTRH

 

  ; ADD 32 TO THE SCRPTR

  LDA #32

  CLC

  ADC SCRPTR

  STA SCRPTR

  LDA #$00

  ADC SCRPTRH

  STA SCRPTRH


  ; DECREMENT THE LINE COUNT AND SEE IF WE'RE

  ; DONE

  DEC IMGHEIGHT

  BNE COPYROW


  RTS


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


; 5x5 pixel images


; Image of a blue "O" on black background

G_O:

DCB $00,$0e,$0e,$0e,$00

DCB $0e,$00,$00,$00,$0e

DCB $0e,$00,$00,$00,$0e

DCB $0e,$00,$00,$00,$0e

DCB $00,$0e,$0e,$0e,$00


; Image of a yellow "X" on a black background

G_X:

DCB $07,$00,$00,$00,$07

DCB $00,$07,$00,$07,$00

DCB $00,$00,$07,$00,$00

DCB $00,$07,$00,$07,$00

DCB $07,$00,$00,$00,$07


; Image of a black square

G_BLANK:

DCB $00,$00,$00,$00,$00 

DCB $00,$00,$00,$00,$00

DCB $00,$00,$00,$00,$00

DCB $00,$00,$00,$00,$00

DCB $00,$00,$00,$00,$00



Now its completed! and the result looks like this!



No comments:

Post a Comment

10th Posting - Project: Stage 3

 Hello All! now we are on the final stage of the project which is project 3. If you remember correctly from my Stage 2 posting, i was able t...