Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Munchor on May 28, 2011, 07:31:32 am

Title: Memory Checker - My first ASM program
Post by: Munchor on May 28, 2011, 07:31:32 am
I finished my first useful ASM program:

Code: [Select]
; Program Name: Memory Checker
; Author: David Gomes
; Version: 0.1
; Written for Doors CS 7.0 and higher
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
 
  set textWrite,(IY + sGrFlags)
  set fracDrawLFont,(IY + fontFlags)
 
  ld a,1
  ld (penCol), a
  ld a,1
  ld (penRow), a
  ld hl,Title
  B_CALL (_VPutS)
 
  ld h,0
  ld l,9
  ld d,95
  ld e,9
  ld a,1
  call fastline
 
  res fracDrawLFont,(IY + fontFlags)
 
  ld a,10
  ld (penRow),a
  ld a,1
  ld (penCol),a
  B_CALL (_memchk)
  call VDispHL
 
  ld a,17
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,OutOf
  B_CALL (_VPutS)
 
  ld a,24
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld de,24756
  ld h,d
  ld l,e
  call VDispHL
 
  call iFastCopy
  B_CALL (_GetKey)
 
  ret
 
Title:
  .db "Memory Checker",0

OutOf:
  .db "out of",0

It only works in DoorsCS7 as it was written for it. It displays the free RAM and the total RAM. So if your free RAM is 11000 it says:

11000
out of
24576

I will be adding more stuff to it as I learn more ASM. What do you think?
Title: Re: Memory Checker - My first ASM program
Post by: aeTIos on May 28, 2011, 09:28:27 am
Ouch. You forgot something very important! The header!
Title: Re: Memory Checker - My first ASM program
Post by: thepenguin77 on May 28, 2011, 09:52:17 am
Indeed, if you are going to use DCS routines, you should probably throw a DCS header on it. The header ensures that shells that don't support DCS funcions won't try to run it. If they do, it will obviously crash (or do something really interesting.)

Also, this line of code made me laugh:
Code: [Select]
  ld de,24756
  ld h,d
  ld l,e
  call VDispHL

I'll let you figure out what's wrong ;) Think of it as an exercise.
Title: Re: Memory Checker - My first ASM program
Post by: aeTIos on May 28, 2011, 09:56:40 am
This:
Code: [Select]
ld a,1
  ld (penCol), a
  ld a,1
  ld (penRow), a
could be
Code: [Select]
ld a,1
ld (penCol), a
ld (penRow), a
because the ld command does not affect registers (except the ones that are loaded to lol)
Title: Re: Memory Checker - My first ASM program
Post by: thepenguin77 on May 28, 2011, 09:58:24 am
Which could be further optimized to:
Code: [Select]
ld hl, 1*256+1 ;penRow * 256 + penCol
ld (penCol), hl
Title: Re: Memory Checker - My first ASM program
Post by: aeTIos on May 28, 2011, 10:00:55 am
Yeah, thats true. You can use that in Axe too. ( Text(Y*256+X) \ Text "STRINGHERE" )
Title: Re: Memory Checker - My first ASM program
Post by: Munchor on May 28, 2011, 03:12:20 pm
I made some updates, what do you think?

Code: [Select]
; Program Name: Memory Checker
; Author: David Gomes
; Version: 0.2
; Written for Doors CS 7.0 and higher
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
.org progstart
.db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
 
  set textWrite,(IY + sGrFlags)
  set fracDrawLFont,(IY + fontFlags)
 
  ld a,1
  ld (penCol), a
  ld (penRow), a
  ld hl,Title
  B_CALL (_VPutS)
 
  ld h,0
  ld l,9
  ld d,95
  ld e,9
  ld a,1
  call fastline
 
  res fracDrawLFont,(IY + fontFlags)
 
  ld a,10
  ld (penRow),a
  ld a,1
  ld (penCol),a
  B_CALL (_memchk)
  call VDispHL
 
  ld a,17
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,OutOf
  B_CALL (_VPutS)
 
  ld a,24
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,24756
  call VDispHL
 
  call iFastCopy
  B_CALL (_GetKey)
 
  res textWrite,(IY + sGrFlags)
 
  ret
 
Title:
  .db "Memory Checker",0

OutOf:
  .db "out of",0

Added an "about" by the way:

Code: [Select]
; Program Name: Memory Checker
; Author: David Gomes
; Version: 0.2
; Written for Doors CS 7.0 and higher
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
.org progstart
.db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
 
  set textWrite,(IY + sGrFlags)
  set fracDrawLFont,(IY + fontFlags)
 
  ld a,1
  ld (penCol), a
  ld (penRow), a
  ld hl,Title
  B_CALL (_VPutS)
 
  ld h,0
  ld l,9
  ld d,95
  ld e,9
  ld a,1
  call fastline
 
  res fracDrawLFont,(IY + fontFlags)
 
  ld a,10
  ld (penRow),a
  ld a,1
  ld (penCol),a
  B_CALL (_memchk)
  call VDispHL
 
  ld a,17
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,OutOf
  B_CALL (_VPutS)
 
  ld a,24
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,24756
  call VDispHL
 
  ld a,57
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,MadeBy
  B_CALL (_VPutS)
 
  call iFastCopy
  B_CALL (_GetKey)
 
  res textWrite,(IY + sGrFlags)
 
  ret
 
Title:
  .db "Memory Checker",0

OutOf:
  .db "out of",0
 
MadeBy:
  .db "by David Gomes",0
Title: Re: Memory Checker - My first ASM program
Post by: thepenguin77 on May 28, 2011, 04:12:26 pm
Looks good, the last thing you should do to bring it up to optimized is change things like
Code: [Select]
;4 bytes
ld d, 95
ld e, 5

;to

;3 bytes
ld de, 95*256+5

And also
Code: [Select]
;10 bytes
ld a, 17
ld (penRow), a
ld a, 1
ld (penCol), a

;to

;6 bytes
ld hl, 17*256+1
ld (penCol), hl

Of course these are just small things. But in big programs, they can start to add up.
Title: Re: Memory Checker - My first ASM program
Post by: Deep Toaster on May 28, 2011, 04:22:11 pm
And don't forget the header :)

Looking great so far. As a suggestion, how about calculating the actual amount of max RAM? It's not always 24,576 bytes. I think there's a pointer with a certain value that you subtract $9D95 from to get the amount of RAM the user could potentially use. Forgot what it was though.
Title: Re: Memory Checker - My first ASM program
Post by: Munchor on May 28, 2011, 04:29:03 pm
And don't forget the header :)

Looking great so far. As a suggestion, how about calculating the actual amount of max RAM? It's not always 24,576 bytes. I think there's a pointer with a certain value that you subtract $9D95 from to get the amount of RAM the user could potentially use. Forgot what it was though.

I was told in Cemetech it was always 24756 :S And the header is DCS7 only now already.