0 Members and 2 Guests are viewing this topic.
.nolist#include "ti83plus.inc"#define ProgStart $9D95.list.org $9D95 - 2 .db t2ByteTok, tAsmCmp b_call(_GrBufClr) ;clear stuff... b_call(_ClrLCDFull) ld a, 255 ld (_time), a ;set _time to 255 (when used in calculation it ends up acting as a lower part of a fixed point number) ld a, (_len) ;_len is always 4 right now. That'll change once I get this thing working. ld (_level), a call LoadVals ;load the _initx and _inity values into _px and _py_tloop: call Bezier ;calculate and plot the point on the curve at _time call LoadVals ;reload the _initx/y values ld hl, _time dec (hl) ;dec _time xor a cp (hl) jr nz, _tloop ;loop until _time is zero call Plot ;plot the first point (shouldn't be necessary, but just in case) ld hl, _px ;load points at _px+(_len) and _py+(_len) into _px and _py ld bc, (_len) dec bc ;_len is the total length, so subtract one to get the last one add hl, bc ;set hl to address of _px+(_len) ld de, _px ldi inc bc ;ldi decrements bc, so add 1 to restore it add hl, bc ld de, _py ldi call Plot b_call(_GrBufCpy) retLoadVals: ld hl, _initx ld de, _px ld bc, 8 ldir retBezier: ld a, 0 ld (_n), a ;reset _n ld hl, _level dec (hl) ;go to next (or first) level iteration ld a, (hl) cp 0 jr nz, bez call Plot ;if the level is zero, draw the point at _px,_py to the graph buffer b_call(_GrBufCpy) ;display for testing purposes jr bez_ret ;end the routinebez: ld hl, (_n) ;for each point p[_n] where _n=0 to _n=_level-1 ld h, 0 ;_n is one byte, so zero out h push hl ;save _n ld de, _px ;we want to calculate the _nth byte starting at _px ;Div_pt has add hl,de in it. call Div_pt ld (hl), a ;save the new x coordinate to _px[_n] pop hl ;restore _n ld de, _py ;now we want the _nth byte starting at _py call Div_pt ld (hl), a ;save the new y coordinate to _py[_n] ld hl, _n ld a, (_level) inc (hl) ;_n=_n+1 cp (hl) jr nc, bez ;loop until _n>=_level-1 call Bezier ;call Bezier again to calculate the next level iterationbez_ret: ld hl, _level inc (hl) ;reset _level to the previous level iteration before returning retDiv_pt: ;input ; de = start address of point array ; hl = value at _n ;output ; a = p[_n]+(p[_n+1]-p[_n])*(_time/256) ; hl = address of p[_n] ;note that p[ ] is either _px[ ] or _py[ ] depending on input de value add hl, de ;find the address of the desired byte push hl pop de inc de ;de = hl+1 ld a, (de) sub (hl) ;subtract p[_n] (at hl) from p[_n+1] (at de) ;a is now the difference of the two points push hl ;save location of p[_n] ld e, 0 jr nc, _pskip ld e, 1 ;if (de)-(hl) is negative, e is 1 neg ;make a positive_pskip:;##################################################################;################################################################## ;This is the part that I guess isn't working ;Basically, I'm using _time as a percentage (where 256 is 100%) ;The point at _time percent of the line between p[_n] and p[_n+1] is calculated here ; and stored in a (later stored in p[_n] back in the main Bezier routine) ;I'm calculating this: ; p[_n]+(p[_n+1]-p[_n])*(_time/256) ld h, a ;make hl fixed point with value a ld l, 0 ld a, (_time) ld d, a ;multiply by _time push de ;save e, which holds the sign call HL_Times_D ;because HL is 2 bytes and D is one byte, this SHOULD be the same ; as multiplying by d as if it was the decimal part of a fixed point number pop de ;restore e ld a, e cp 0 ;check for negative ld a, h ;in case of negative, get the value to invert jr z, _nskip neg ;if a was negative before, make it negative again_nskip: pop hl add a,(hl) ;add the original p[_n] value ret;##################################################################;##################################################################Plot: ld a, (_py) ;get the y coordinate into l ld l, a or a ret m ;ret if negative cp 64 ret nc ;ret if y>=64 ld a, (_px) ;get x or a ret m ;ret if negative cp 96 ret nc ;ret if x>=96 call GetPixel ;turn on pixel (x,y) or (hl) ld (hl), a retGetPixel: ;this came from the "Learn TI-83/84+ ASM in 28 days" or whatever guide ;a = x coordinate ;l = y coordinate ld h, 0 ld d, h ld e, l add hl, hl add hl, de add hl, hl add hl, hl ld e, a srl e srl e srl e add hl, de ld de, PlotSScreen add hl, de and 7 ld b,a ld a, $80 ret z__gloop: rrca djnz __gloop retHL_Times_D: ;this came from the "Learn TI-83/84+ ASM in 28 days" or whatever guide ;in the guide it was DE_Times_A, but I was already using HL and D for division ; so I thought it was a good idea to just keep those values ld a, d ld de, 0 ex de, hl ld b, 8__mloop: rrca jr nc, __mskip add hl, de__mskip: sla e rl d djnz __mloop retDiv_HL_D: ;this came from the "Learn TI-83/84+ ASM in 28 days" or whatever guide xor a ld b, 16__dloop: add hl, hl rla jr c, __overflow cp d jr c, __dskip__overflow: sub d inc l__dskip: djnz __dloop ret_time: .db 0_level: .db 0 ;control point iteration level_n: .db 0 ;control point to calculate at any given time_len: .dw 4 ;number of control points for the curve_initx: .db 4, 7, 13, 20 ;control point x values_inity: .db 6, 23, 19, 2 ;control point y values_px: .db 0, 0, 0, 0 ;x values for calculations_py: .db 0, 0, 0, 0 ;y values for calculations.end.end
Blasphemy! People spelled my name incorrectly, twice!
ld h, a ld l, 0
ld h, 0 ld l, a
I don't know any asm at all, so I'm of even less help, but I can point you to a webpage I found which provided the algorithm I adapted: http://freespace.virgin.net/hugo.elias/graphics/x_bezier.htm
Also, it's pretty easy to remember that the columns start at $20 and the rows start at $80.