i cant get this piece of assembly to do what i want

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
777
Manic Miner
Posts: 513
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

i cant get this piece of assembly to do what i want

Post by 777 »

i want it to count up through the character set until it gets to the tokens. but for some reason it just print 9's.

here:

Code: Select all

org 40000
ld a,32
call $0daf
loop
inc a
rst 16
jr loop
any ideas?
Last edited by 777 on Mon Jul 10, 2023 3:09 pm, edited 1 time in total.
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
User avatar
Alessandro
Dynamite Dan
Posts: 1910
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: i can get this piece of assembly to do what i want

Post by Alessandro »

Code: Select all

  ORG 40000

  CALL 3503
  LD A,32
LOOP:
  CP 128
  RET Z
  PUSH AF
  RST 16
  POP AF
  INC A
  JR LOOP
User avatar
SkoolKid
Manic Miner
Posts: 407
Joined: Wed Nov 15, 2017 3:07 pm

Re: i can get this piece of assembly to do what i want

Post by SkoolKid »

The contents of the accumulator are being corrupted by the routine calls. Try this:

Code: Select all

  org 40000
  call $0daf
  ld a,32
loop:
  push af
  rst 16
  pop af
  inc a
  jp p,loop
  ret
SkoolKit - disassemble a game today
Pyskool - a remake of Skool Daze and Back to Skool
User avatar
777
Manic Miner
Posts: 513
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: i cant get this piece of assembly to do what i want

Post by 777 »

thanks. i had a feeling that was what the problem was...
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
User avatar
Alessandro
Dynamite Dan
Posts: 1910
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: i cant get this piece of assembly to do what i want

Post by Alessandro »

You also need to check if A hits 128 (CP 128), exiting the loop in that case (RET Z), if you want to print the character set only.
User avatar
777
Manic Miner
Posts: 513
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: i cant get this piece of assembly to do what i want

Post by 777 »

Alessandro wrote: Mon Jul 10, 2023 3:18 pm You also need to check if A hits 128 (CP 128), exiting the loop in that case (RET Z), if you want to print the character set only.
thank you. how would i incorporate code to print to the screen without using rom calls?

i have this:

Code: Select all

org 40000
LD A, 65                ; Character to print
                     ;   LD D, 1                 ; Y position
                    ;    LD E, 15                ; X position
                        CALL Print_Char         ; Print the character
                        RET
;
; Print a single character out to a screen address
;  A: Character to print
;  D: Character Y position
;  E: Character X position
;
Print_Char:             LD HL, 0x3C00           ; Character set bitmap data in ROM
                        LD B,0                  ; BC = character code
                        LD C, A
                        SLA C                   ; Multiply by 8 by shifting
                        RL B
                        SLA C
                        RL B
                        SLA C
                        RL B
                        ADD HL, BC              ; And add to HL to get first byte of character
                     ;   CALL Get_Char_Address   ; Get screen position in DE
                        LD B,8                  ; Loop counter - 8 bytes per character
Print_Char_L1:          LD A,(HL)               ; Get the byte from the ROM into A
                        LD (DE),A               ; Stick A onto the screen
                        INC HL                  ; Goto next byte of character
                        INC D                   ; Goto next line on screen
                        DJNZ Print_Char_L1      ; Loop around whilst it is Not Zero (NZ)
                        RET
 
; Get screen address from a character (X,Y) coordinate
; D = Y character position (0-23)
; E = X character position (0-31)
; Returns screen address in DE
;
Get_Char_Address:       LD A,D
                        AND %00000111
                        RRA
                        RRA
                        RRA
                        RRA
                        OR E
                        LD E,A
                        LD A,D
                        AND %00011000
                        OR %01000000
                        LD D,A
                        RET                             ; Returns screen address in DE
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
User avatar
Morkin
Bugaboo
Posts: 3277
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: i cant get this piece of assembly to do what i want

Post by Morkin »

If you've got your own graphics, it's a bit shorter as you don't need to faff around calculating the CHARS value.

Try sticking the graphics in a DEFB at the end of the routine and then loading HL with the label, something like:

Code: Select all

org 40000
                        LD D, 1                 ; Y position
                        LD E, 15                ; X position
                        CALL Print_Char         ; Print the character
                        RET
;
; Print a single character out to a screen address;
;  D: Character Y position
;  E: Character X position
;
Print_Char:             LD HL, Graphic      ;    ** Where your graphic is stored **

                        CALL Get_Char_Address   ; Get screen position in DE
                        LD B,8                  ; Loop counter - 8 bytes per character
Print_Char_L1:          LD A,(HL)               ; Get the byte from the ROM into A
                        LD (DE),A               ; Stick A onto the screen
                        INC HL                  ; Goto next byte of character
                        INC D                   ; Goto next line on screen
                        DJNZ Print_Char_L1      ; Loop around whilst it is Not Zero (NZ)
                        RET
 
; Get screen address from a character (X,Y) coordinate
; D = Y character position (0-23)
; E = X character position (0-31)
; Returns screen address in DE
;
Get_Char_Address:       LD A,D
                        AND %00000111
                        RRA
                        RRA
                        RRA
                        RRA
                        OR E
                        LD E,A
                        LD A,D
                        AND %00011000
                        OR %01000000
                        LD D,A
                        RET                             ; Returns screen address in DE

Graphic:	DEFB 255, 129, 129, 129, 129, 129, 129, 255    
You'll need to un-comment out some of those lines.
My Speccy site: thirdharmoniser.com
Post Reply