greyelf@wpi.WPI.EDU (Michael J Pender) (11/04/90)
This is a library of graphics functions I wrote for interfacing with Hyper C prodos. It would seem redundant to shrinkit it only to convert it to text again for mailing, so here it is as a source file. In addition it should answer any questions people may have about how to use graphics routines from assembler. On my machine I call it gr.a, I use the ca utility I wrote (available from plains.nodak.edu, I don't have it on the mainframe). to make a library called gr.o, and then I just add &gr.o on the end of my cc file with the other libraries. If there is any interest I also have cat, more and pr (output to printer) utilities I wrote. I don't have the scanf function, nor the documentation, though I wish I did. cat and more are very useful, and the ones I wrote have a filter so as not to make mush of the system... --- Michael J Pender Jr Box 1942 c/o W.P.I. Part of this D- belongs to greyelf@wpi.bitnet 100 Institute Rd. God... greyelf@wpi.wpi.edu Worcester, Ma 01609 - B. Simpson ; This is machine language code designed to interface graphics with ; the HyperC Prodos language. The code includes routines for lo-res ; and hi-res graphics. The functions supported work as follows: ; ; void settxt(void) Selects text screen mode ; void home(void) Clears screen, places cursor in upper left corner ; void setgr(void) Sets lo-res graphics mode, clears screen to black ; void sethgr(void) Sets hi-res graphics mode, page one, clears screen ; void sethgr2(void) Sets hi-res graphics mode, page two, clears screen ; void color(char colr) Sets lo-res plotting color ; void hcolor(char colr) Sets hi-res plotting color ; void bkgnd(void) Sets background to last hi-res color plotted ; void plot(char x, char y) Plots a point on lo-res screen ; void hplot(int x, char y) Plots a point on hi-res screen ; void hplotto(int x, char y) Plots a line to the point on the hi-res screen ; void hlin(char xlow, char xhigh, char y) ; Plots an horizontal line from xlow to xhigh at vertical line y ; void vlin(char ylow, char yhigh, char x) ; Plots a vertical line from ylow to yhigh at horizontal line x ; void scrn(char x, char y, char *result) ; Reads color of point on lo-res screen and stores color number at ; address passed in result. ; ; NOTE: To prevent use of hi-res functions from eating your program ; you must use the -tb option on the linker to protect the space for ; hi-res pages one and/or two. The -tb option sets the start of program ; space. ; To reserve page one: ; lnk -tb0x4000 <any other switches> <file name> ; To reserve both pages: ; lnk -tb0x6000 <any other switches> <file name> ; ; My thanks to Ben Liblit who told me about the linker switch. ; Also, I must credit Robert R. Devine of Nibble magazine, ; for much of the information I used to make the graphics routines ; was from his article "The Basic-Assembly Connection," Nibble Magazine, ; June 1986, pp 86-91. ; ; I have not tested all the routines in this library, I make no guarantees. ; Further, I do not have the documentation for Hyper C, this was improvised. ; Therefore I cannot give copies of documentation to anyone else. ; However if someone has documentation for Hyper C I would gladly pay ; Xeroxing and mailing expenses. ; ; Mike Pender a.k.a. greyelf@wpi.wpi.edu ; 1480 Mapleton Avenue ; Suffield, CT, 06078 ; ; This library is presented as-is. I have not tested all the functions. ; I do reserve all commercial rights, I put a lot of time into this. ; But for private use, please feel free to copy and use these routines ; as you see fit. If you do something really cool using these routines ; I'd appreciate being give appropriate credit. .nolist sp = 0xf4 sph = sp+1 fp = sp-2 fph = fp+1 pc = fp-2 pch = pc+1 r1 = pc-2 r1h = r1+1 r2 = r1-2 r2h = r2+1 r3 = r2-2 r3h = r3+1 r4 = r3-2 r4h = r4+1 jp = r4-2 jph = jp+1 smask = jp-2 smaskh = smask+1 dsply = smask-32 rp = dsply-2 .list .even .entry _settxt ; void settxt(); _settxt: ; Changes back to text mode from graphics. ; ;********************************************************************* ; lda #0 ; This value represents the number or number of tay ; bytes of parameters returned. jsr Alnk ; You MUST invoke the Alnk. ; ;********************************************************************* ; jsr 0xfb2f ; Call ROM text routine. jmp Artn ; Return to caller .even .entry _home ; void home(); _home: ; Clears screen, homes cursor. lda #0 ; Indicate we will not be passing back any parameters. tay jsr Alnk jsr 0xfc58 ; Call ROM home routine. jmp Artn ; Return to caller .even .entry _setgr ; void setgr(); _setgr: ; Sets lo-res graphics mode. lda #0 ; Indicate we will not be passing back any parameters. tay jsr Alnk jsr 0xfb40 ; Call ROM gr routine. jmp Artn ; Return to caller .even .entry _sethgr ; void sethgr(); _sethgr: ; Sets hi-res graphics mode. lda #0 ; Indicate we will not be passing back any parameters. tay jsr Alnk jsr 0xf3e2 ; Call ROM hgr routine. jmp Artn ; Return to caller .even .entry _sethgr2 ; void sethgr2(); _sethgr2: ; Sets up full-screen hi-res page 2 graphics lda #0 ; Indicate we will not be passing back any parameters. tay jsr Alnk jsr 0xf3d8 ; Call ROM hgr2 routine. jmp Artn ; Return to caller .even .entry _color ; void color(char colr); _color: ; Sets lo-res plotting color to value passed. lda #0 ; Indicate we will not be passing back any tay ; parameters. jsr Alnk ldy #4 ; Fetch color value lda [sp],y cmp #0x10 ; Verify color value within range bcs _exitcolor jsr 0xf864 ; Call ROM color routine _exitcolor: jmp Artn ; Return to caller .even .entry _hcolor ; void hcolor(char colr); _hcolor: ; Sets hi-res plotting color to value passed. lda #0 ; Indicate we will not be passing back any tay ; parameters. jsr Alnk ldy #4 ; Fetch color value lda [sp],y cmp #0x08 ; Verify color value within range bcs _exithcolor tax ; Value must be loaded into x register jsr 0xf6ec ; Call ROM hcolor routine _exithcolor: jmp Artn ; Return to calling program .even .entry _bkgnd ; void bkgnd(void); _bkgnd: ; Sets hi-res plotting plane color to last color ; plotted. lda #0 ; Indicate we will not be passing back any tay ; parameters. jsr Alnk jsr 0xf3f6 ; Call ROM bkgnd routine jmp Artn ; Return to calling program .even .entry _plot ; void plot(char x, char y); _plot: ; Plots a single lo-res point on the screen. lda #0 ; Indicate we will not be passing back any parameters. tay jsr Alnk ldy #4 ; Fetch x coordinate lda [sp],y cmp #40 ; Verify x coordinate within range bcs _exitplot sta r2 ; Save x coordinate value ldy #6 ; Fetch y coordinate lda [sp],y cmp #48 ; Verify y coordinate within range bcs _exitplot ldy r2 ; Retrieve x coordinate value jsr 0xf800 ; Call ROM plot routine. _exitplot: jmp Artn ; Return to caller .even .entry _hplot ; void hplot(int x, char y); _hplot: ; Plots a single hi-res point on the screen. lda #0 ; Indicate we will not be passing back any parameters. tay jsr Alnk ldy #5 ; Fetch x coordinate hi byte lda [sp],y cmp #2 ; Verify x coordinate within range bcs _exithplot sta r1h ; Save x hi byte ldy #4 ; Fetch x coordinate low byte lda [sp],y sta r1 ; Save x low byte lda r1h ; Retrieve x hi byte beq hp1 ; If hi byte = 0 skip this... lda r1 ; Retrieve x low byte cmp #0x18 ; Verify x coordinate within range bcs _exithplot hp1: ldy #6 ; Fetch y coordinate byte lda [sp],y cmp #0xc0 ; Verify y coordinate within range bcs _exithplot ; Leave y coordinate value in accumulator ldx r1 ; Retrieve low byte of of x coordinate ldy r1h ; Retrieve high byte of x coordinate jsr 0xf457 ; Call ROM hplot routine. _exithplot: jmp Artn .even .entry _hplotto ; void hplotto(int x, char y); _hplotto: ; Plots a line to the point on the hi-res screen. lda #0 ; Indicate we will not be passing back any parameters. tay jsr Alnk ldy #5 ; Fetch x coordinate hi byte lda [sp],y cmp #2 ; Verify x coordinate within range bcs _exithplto sta r1h ; Save x hi byte ldy #4 ; Fetch x coordinate low byte lda [sp],y sta r1 ; Save x low byte lda r1h ; Retrieve x hi byte beq hpt1 ; If hi byte = 0 skip this... lda r1 ; Retrieve x low byte cmp #0x18 ; Verify x coordinate within range bcs _exithplto hpt1: ldy #6 ; Fetch y coordinate byte lda [sp],y cmp #0xc0 ; Verify y coordinate within range bcs _exithplto tay ; Transfer y coordinate to y register lda r1 ; Retrieve low byte of of x coordinate ldx r1h ; Retrieve high byte of x coordinate jsr 0xf53a ; Call ROM hplot_to routine. _exithplto: jmp Artn ; Return to caller .even .entry _hlin ; void hlin(char xlow, char xhigh, char y) _hlin: ; Draws a horizontal line between xlow and xhigh lda #0 ; at vertical position y tay jsr Alnk ldy #6 ; Fetch xhigh lda [sp],y cmp #40 ; Verify xhigh within range bcs _exithlin sta 0x2c ; Store in position ldy #4 ; Fetch xlow lda [sp],y cmp #40 ; Verify xlow within range bcs _exithlin sta r2 ; Save xlow ldy #8 ; Get y position lda [sp],y cmp #48 ; Y within range? bcs _exithlin ldy r2 ; Retrieve xlow jsr 0xf819 ; Call ROM hlin routine _exithlin: jmp Artn .even .entry _vlin ; void vlin(char ylow, char yhigh, char x) _vlin: ; Draws a vertical line between ylow and yhigh lda #0 ; at horizontal position x tay jsr Alnk ldy #6 ; Get yhigh value lda [sp],y cmp #48 ; Verify yhigh within range bcs _exitvlin sta 0x2d ldy #8 ; Get x value lda [sp],y cmp #40 ; Verify x within range bcs _exitvlin sta r2 ; Save x coordinate ldy #4 ; Get ylow value lda [sp],y cmp #48 ; Verify ylow within range bcs _exitvlin ldy r2 ; Retrieve x coordinate jsr 0xf828 ; Call ROM vlin routine _exitvlin: jmp Artn ; Return to caller .even .entry _scrn ; void scrn(char x, char y, char *result); _scrn: ; Returns the color of the point indicated lda #0 ; in result. Pass address of result to scrn. tay jsr Alnk ldy #8 ; Fetch address to deposit result lda [sp],y sta r3 ; Save in register 3 for indirect access iny ; Fetch high byte of result address lda [sp],y sta r3h ; Save in high byte of register 3 for later access ldy #4 ; Fetch x value lda [sp],y cmp #40 ; Is x value legal? bcs _exitscrn sta r2 ; Preserve value ldy #6 ; Fetch y value lda [sp],y cmp #48 ; Is y value legal? ldy r2 ; Retrieve x value jsr 0xf871 ; Call ROM scrn routine ldy #0 ; Prepare to store scrn result sta [r3],y ; Store result value _exitscrn: jmp Artn ; Return to caller -- --- Michael J Pender Jr Box 1942 c/o W.P.I. Part of this D- belongs to greyelf@wpi.bitnet 100 Institute Rd. God...