Author Topic: Drawing Loop in Assembly  (Read 1098 times)

0 Members and 1 Guest are viewing this topic.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.921
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1132
  • Likes Given: 1906
Drawing Loop in Assembly
« on: 13:05, 29 September 10 »
I wrote this a few years ago which Draws a sequence of lines from the data I've given it and it works well (it's quicker than it's BASIC equivalent), though I was wondering if could be improved.
Here's the code which I extensively commented:
Code: [Select]
;; Drawing Loop in Assembly
;; CP/M User
ORG &4000
  ld a,1
  call &bbde           ;; Set Graphics Pen
  ld de,100
  ld hl,100
  call &bbc0           ;; Move Absolute Position
  ld b,&4              ;; Number of times to loop
  ld de,data_xpos      ;; Load Coordinate Position into DE
  ld hl,data_ypos      ;; Load Coordinate Position into HL
  ld (adrxpos),de
  ld (adrypos),hl      ;; Store address of data
.loop                  ;; Begin of Loop
   ld de,(adrxpos)     ;; Get contents of address of Data
                       ;; into DE
   inc de
   inc de              ;; Increase this by 2 data is 2 bytes in size
   ld (adrxpos),de     ;; Put this new address into address of data
   ld hl,(adrypos)     ;; Put address of ypos into hl
   inc hl
   inc hl              ;; Increase this by 2 same as DE
   ld (adrypos),hl     ;; Put this new address into address of data
   push bc             
   call do_draw        ;; Call this routine
   pop bc
  djnz loop            ;; Go back if B is greater than 0
 ret                   ;; Otherwise Exit
  ld b,(hl)            ;; Store Contents of Lower HL (YPOS Data) into B
  inc hl               ;; Increase address of HL
  ld c,(hl)            ;; Store Contents of Upper HL (YPOS Data) into C
  ld hl,ypos           ;; Get Lower address of HL
  ld (hl),b            ;; And put value of B into it
  inc hl               ;; Increase this by 1
  ld (hl),c            ;; Now put value of C into it
  ;; What this has effecively done is move the contents
  ;; of ypos in particular, from one memory location to
  ;; another fixed location, for where the data can go
  ;; into the registers & then do a call to Line Absolute
  ;; (&BBF6). I used to try doing this while moving the
  ;; address (e.g. Get contents of first xpos & ypos,
  ;; then move onto the second), course it maybe possible,
  ;; but I found this much easier.
  ex de,hl        ;; Exchange Contents of DE & HL
  ld b,(hl)            ;; Put Contents of HL (which was DE) into B
  inc hl               ;; Increase HL by 1
  ld c,(hl)            ;; Put that into C
  ld hl,xpos           ;; Get address of xpos
  ld (hl),b           
  inc hl
  ld (hl),c            ;; Put contents into it
  ;; This is really just the same as above apart from getting the
  ;; address of xpos, I left it with this, instead of trying to
  ;; Poke my own program (by replacing YPOS address with XPOS). 
  ld de,(xpos)         ;; So with all the data being at XPOS &
  ld hl,(ypos)         ;; YPOS, I can do a call for Absolute Line
  call &bbf6
;; Data Areas
.xpos  defw 0          ;; Section where XPOS & YPOS goes
.ypos  defw 0
.adrxpos defw 0        ;; This is the address of the data for XPOS
.adrypos defw 0        ;; Same as Above except for YPOS
 defw 0                ;; Leave this line here
 defw 100
 defw 200              ;; Sample Data (XPOS)
 defw 200
 defw 100
 defw 0                ;; Leave this line alone
 defw 200
 defw 200              ; Sample Data (YPOS)
 defw 100
 defw 100

I guess it doesn't really matter if it's not enhanced, just thought that since my Assembly isn't the best, some simple tweaking which involves code I'm unfamiliar with would speed the code up somewhat!  :-\  I did make another version somewhere which uses GRA LINE RELATIVE, in which the data changes somewhat, I made it as a routine I could use to generate some simple graphics in the game I'll eventually get around to making.  :-[
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3