STAR TIP 11 by Andrew Whittaker Huraayyhhh! Yet another Star Tip for you to drool over this month. Number eleven too. I wonder if we'll get into the twenties by the end of the year. Who knows? I certainly don't. This Star Tip is by Andrew Whittaker and it's a simple, but essential print routine. Andrew Until Christmas, Andrew was a member of the highly skilled and prolific Graftgold programming team at Firebird. He helped in the coding of such fruit-cakes as Flying Shark and Magnetron. He's currently working freelance (I love that word), on arcade titles. Thanks billions Andrew and keep them coming whenever you feel the urge. Method This is the first source code listing we've had for yonks, mainly because its un-documented ones that I receive all the time. To use it you must use an assembler (any one will do), and then save the source off to tape. Printing The character print routine in the ROM (rst 10), is notoriously slow, so this routine replaces that snail of a program, at the expense of error handling and control code handling. To print a character you must load the accumulator with the ASCII code of the character and then call the print routine. LD A,"B" CALL PRINT This'll print a "B" on the screen. To specify PRINT AT co-ordinates, you must use the code 22, followed by a row and a column value. So to print the letter "B" at screen co-ords 7,10 use: LD A,22 CALL PRINT LD A,7 CALL PRINT LD A,10 CALL PRINT LD A,"B" CALL PRINT Alternatively a direct screen address can be passed to the routine by using: LD HL,screen addr LD (XYPOS), HL There's also a string print routine which prints the string pointed to by HL, and with the byte 255 as an end marker: LD HL,MESSAGE CALL STRPRNT RET MESSAGE DEFM 22,11,6,"Your Sinclair",255 This is the equivalent to PRINT AT 11,6;"Your Sinclair" in Basic. [I changed STRPRNT to save and restore HL', to avoid a crash on returning to BASIC. JimG] So there you are. Source Code Listing 0000 00000 ;Star Tip 11 0000 00000 ;Text Print Handler 0000 00000 ;by Andrew Whittaker 0000 00000 ;from Your Sinclair, Aug'88 0000 00000 ; 0000 00000 ;Using OCP Editor/Assembler 0000 00000 ; 0000 00000 ;!! WARNING !! 0000 00000 ;The PRINT routine corrupts HL' 0000 00000 ;and so causes a crash on return 0000 00000 ;to BASIC. Anything using PRINT 0000 00000 ;needs to save HL' and restore 0000 00000 ;it before returning to BASIC. 0000 00000 ; [JimG] 0000 00000 ; 0000 00000 ; input: character code in A 0000 00000 ;output: chr to screen 0000 00000 ; print pos advanced 0000 00000 ;alternate registers corrupted 0000 00000 org 65000 FDE8 D9 00000 PRINT exx FDE9 6F 00000 ld l,a FDEA 00000 ; FDEA 00000 ;test for x-y update FDEA 00000 ; FDEA 3A47FE 00000 ld a,(PFLAG) FDED A7 00000 and a FDEE 2034 00000 jr nz,CONTRL FDF0 7D 00000 ld a,l FDF1 00000 ; FDF1 00000 ;test for CHR$ 22 FDF1 00000 ; FDF1 FE16 00000 cp 22 FDF3 2828 00000 jr z,GETXY FDF5 00000 ; FDF5 00000 ;find char definition FDF5 00000 ; FDF5 2600 00000 ld h,0 FDF7 29 00000 add hl,hl FDF8 29 00000 add hl,hl FDF9 29 00000 add hl,hl FDFA ED5B48FE 00000 ld de,(FONT) FDFE 19 00000 add hl,de FDFF ED5B4AFE 00000 ld de,(XYPOS) FE03 00000 ; FE03 00000 ;print the character FE03 00000 ; FE03 0608 00000 ld b,8 FE05 7E 00000 PRLOOP ld a,(hl) FE06 12 00000 ld (de),a FE07 14 00000 inc d FE08 23 00000 inc hl FE09 10FA 00000 djnz PRLOOP FE0B 00000 ; FE0B 00000 ;increment the print position FE0B 00000 ; FE0B 15 00000 dec d FE0C 7A 00000 ld a,d FE0D 0F 00000 rrca FE0E 0F 00000 rrca FE0F 0F 00000 rrca FE10 57 00000 ld d,a FE11 13 00000 inc de FE12 7A 00000 ld a,d FE13 87 00000 add a FE14 87 00000 add a FE15 87 00000 add a FE16 57 00000 ld d,a FE17 ED534AFE 00000 ld (XYPOS),de FE1B 00000 ; FE1B 00000 ;exit the calling routine FE1B 00000 ; FE1B D9 00000 exx FE1C C9 00000 ret FE1D 00000 ; FE1D 00000 ;signal next two bytes are FE1D 00000 ;x-y coordinates FE1D 00000 ; FE1D 3E02 00000 GETXY ld a,2 FE1F 3247FE 00000 ld (PFLAG),a FE22 D9 00000 exx FE23 C9 00000 ret FE24 00000 ; FE24 00000 ;update row and column (x+y) FE24 00000 ; FE24 3D 00000 CONTRL dec a FE25 3247FE 00000 ld (PFLAG),a FE28 2812 00000 jr z,COL FE2A 00000 ; FE2A 00000 ;set new row value FE2A 00000 ; FE2A 7D 00000 GETROW ld a,l FE2B E618 00000 and 0011000b FE2D F640 00000 or 1000000b FE2F 67 00000 ld h,a FE30 7D 00000 ld a,l FE31 E607 00000 and 0000111b FE33 0F 00000 rrca FE34 0F 00000 rrca FE35 0F 00000 rrca FE36 6F 00000 ld l,a FE37 224AFE 00000 ld (XYPOS),hl FE3A D9 00000 exx FE3B C9 00000 ret FE3C 00000 ; FE3C 00000 ;get new column value FE3C 00000 ; FE3C 3A4AFE 00000 COL ld a,(XYPOS) FE3F E6E0 00000 and 11100000b FE41 B5 00000 or l FE42 324AFE 00000 ld (XYPOS),a FE45 D9 00000 exx FE46 C9 00000 ret FE47 00000 ; FE47 00000 ;variables FE47 00000 ; FE47 00 00000 PFLAG defb 0 FE48 003C 00000 FONT defw 3c00h FE4A 0040 00000 XYPOS defw 16384 FE4C 00000 ; FE4C 00000 ;PRINT A STRING FE4C 00000 ;entry:- addr of string in HL FE4C 00000 ;terminated by a FF byte FE4C 00000 ;exit:- string printed to screen FE4C 00000 ;accepts xy pos via CHR$ 22,x,y FE4C 00000 ;corrupts HL,A,alternate set FE4C 00000 ; FE4C 2161FE 00000 MESPRT ld hl,MESSGE FE4F D9 00000 STRPRT exx FE50 E5 00000 push hl FE51 D9 00000 exx FE52 7E 00000 STRPR2 ld a,(hl) FE53 FEFF 00000 cp 255 FE55 2806 00000 jr z,STRPR3 FE57 CDE8FD 00000 call PRINT FE5A 23 00000 inc hl FE5B 18F5 00000 jr STRPR2 FE5D D9 00000 STRPR3 exx FE5E E1 00000 pop hl FE5F D9 00000 exx FE60 C9 00000 ret FE61 00000 ; FE61 160B06 00000 MESSGE defb 22,11,6 FE64 596F7572 00000 defm 'Your Sinclair' FE68 2053696E FE6C 636C6169 FE70 72 FE71 FF 00000 defb 255