Using DF_CC with ASM

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
swensont
Posts: 76
Joined: Tue Jan 18, 2011 4:55 am
Location: SF Bay Area
Contact:

Using DF_CC with ASM

Post by swensont »

I want to be able to see what character is at X,Y location on the screen. The system variable DF_CC contains the address of the next location to print. If I do a PRINT AT, but don't print, then the value at the location pointed by DF_CC should be at X,Y. For some reason I can't get it to work in ASM, but I can get it to work in BASIC.

Here is the BASIC program:

Code: Select all

10 print at 10,10;"*"
15 print at 10,10;
20 let x = peek 16398 + 256*peek 16399
30 let y = peek(x)
40 print at 0,0;x
50 print at 1,0;y
The result prints "23" at the end, which is the code for asterisk.

Here is the ASM:

Code: Select all

     LD     BC,$0A0A    ; set print position
     CALL   PRINTAT
     LD     A,$17       ; print asterisk
     CALL   PRINT

     LD     BC,$0A0A
     CALL   PRINTAT     ; set new PRINTAT location
     LD     A,(16398)   ; Get value at new position
     PUSH   AF
     LD	BC,$0000    ; set print to 0,0
     CALL	PRINTAT
     POP    AF
     CALL   PRINT       ; print at 0,0 what is in DF_CC
			
     RET                ; Return to BASIC
This does not print an asterisk, but instead I get a "\". I'm not sure what is going wrong.

Thanks,

Tim
dr beep
Posts: 2339
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Using DF_CC with ASM

Post by dr beep »

You miss 1 step

Code: Select all

     LD     BC,$0A0A
     CALL   PRINTAT     ; set new PRINTAT location
     LD     HL,(16398)   ; Get new position
     LD	A,(HL)	; get value

swensont
Posts: 76
Joined: Tue Jan 18, 2011 4:55 am
Location: SF Bay Area
Contact:

Re: Using DF_CC with ASM

Post by swensont »

The doctor has spoken. I guess I don't need a second opinion. :-)

Tim
User avatar
XavSnap
Posts: 2062
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.
Contact:

Re: Using DF_CC with ASM

Post by XavSnap »

Hi Tim,

Yes, your code is wrong:

Code: Select all

     LD     BC,$0A0A
     CALL   PRINTAT     ; set new PRINTAT location
     LD     A,(16398)   ; Get value at new position
The value at 16398 is "20", from the DF_CC value... ($42"20" ? or something else.)
LD A,(16398) ; Get value at new position
Don't get the indirect value at the DF_CC target address, but at 16398 !

Dr.Beep use the indirect HL value :

Code: Select all

     LD     HL,(16398)   ; Get new position
     LD	A,(HL)	; get value
HL=Target and A, the value in this target.

LD A,(16398)= the byte in 16398 in the memory !
You had to retrive the offset in 16398, and extract the value in HL.
LD A,(HL) ; only HL,BC,DE or IX/IY/SP register are suitable to get an indirect value.

LD A,(16398 = the value at the 16398 memory offset.
LD A,(HL)= the value at the HL=16398 memory offset, the displayed character in the screen memory location from DF_CC.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
dr beep
Posts: 2339
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Using DF_CC with ASM

Post by dr beep »

dr beep wrote: Wed Dec 21, 2022 7:36 pm You miss 1 step

Code: Select all

     LD     BC,$0A0A
     CALL   PRINTAT     ; set new PRINTAT location
     LD     HL,(16398)   ; Get new position
     LD	A,(HL)	; get value

After the CALL to PRINTAT the HL-register is already pointing to the screenposition.
so the 3rd line is not needed at all.
Post Reply