; This program was written by ANDREW PEARCE in collaboration with JAMES PATTINSON
; in June 1996 - We accept no responsibilty for anything bad happening to your 
; calculator as a result of running this. (The worst that can happen is a frozen
; calc.  - just take the batteries out and press "on" a few times, then replace the
; batteries.

; It allows you to send bytes to a specific port on the TI85. OK - it's crap, but
; we've only just got our TI-85's and this is the first assembly prog we've done,
; except for "Hello World" !!

; Feel free to edit this prog as you wish, but the copyright remains with us 
; so send fixes / changes / rewrites / additions to me, Misterdata@aol.com.

; COMING SOON in version 3:	Efficient Code!!
:				Commented Code!!
;				More Features!!!

; Just whack it through TASM, String85 it, and totally freeze your calc!
; Details of ports can be found in TI-PORTS.TXT.

; Thanx go to:	Dan Eble, Magnus Hagander, Rob Taylor for ZShell
: 		Various other people for Excellent Docs / Reference files!

#include "TI-85.h"

.org 0
.db "BUGGER UP v2.0",0

	ROM_CALL(CLEARLCD)		
	res 1,(IY+0D)		
	ld hl,(PROGRAM_ADDR)	
	ld de,Hello		
	add hl,de		
	ld a,1			
	ld (CURSOR_COL),a	
	ld (CURSOR_ROW),a		
	ROM_CALL(D_ZT_STR)		

	CALL_(KeyLoop)				
	ld ($80DF),a			  
	ld ($80E1),a			
	CALL_(DispHL)			
EntLoop:
	call GET_KEY
	cp $09
	jr nz,EntLoop

	ld a,($80df)
	ld c,a
	in a,(c)
	ld ($80E1),a
	CALL_(DispHL)
EntLoop2:
	call GET_KEY
	cp $09
	jr nz,EntLoop2

	ld hl,(PROGRAM_ADDR)
	ld de,Hello2
	add hl,de
	ld a,1
	ld (CURSOR_COL),a
	ld (CURSOR_ROW),a
	ROM_CALL(D_ZT_STR)	
	CALL_(BitLoop)
	ld hl,$80E0
	cp 1
	jr z,setlbl7
	res 7,(HL)
	ld ($80E1),a
	CALL_(DispHL)
	jr reslbl7
setlbl7:
	set 7,(HL)
	ld ($80E1),a
	CALL_(DispHL)
reslbl7:	
	CALL_(BitLoop)
	ld hl,$80E0
	cp 1
	jr z,setlbl6
	res 6,(HL)
	ld ($80E1),a
	CALL_(DispHL)
	jr reslbl6
setlbl6:
	set 6,(HL)
	ld ($80E1),a
	CALL_(DispHL)
reslbl6:	
	CALL_(BitLoop)
	ld hl,$80E0
	cp 1
	jr z,setlbl5
	res 5,(HL)
	ld ($80E1),a
	CALL_(DispHL)
	jr reslbl5
setlbl5:
	set 5,(HL)
	ld ($80E1),a
	CALL_(DispHL)
reslbl5:	
	CALL_(BitLoop)
	ld hl,$80E0
	cp 1
	jr z,setlbl4
	res 4,(HL)
	ld ($80E1),a
	CALL_(DispHL)
	jr reslbl4
setlbl4:
	set 4,(HL)
	ld ($80E1),a
	CALL_(DispHL)
reslbl4:	
	CALL_(BitLoop)
	ld hl,$80E0
	cp 1
	jr z,setlbl3
	res 3,(HL)
	ld ($80E1),a
	CALL_(DispHL)
	jr reslbl3
setlbl3:
	set 3,(HL)
	ld ($80E1),a
	CALL_(DispHL)
reslbl3:	
	CALL_(BitLoop)
	ld hl,$80E0
	cp 1
	jr z,setlbl2
	res 2,(HL)
	ld ($80E1),a
	CALL_(DispHL)
	jr reslbl2
setlbl2:
	set 2,(HL)
	ld ($80E1),a
	CALL_(DispHL)
reslbl2:	
	CALL_(BitLoop)
	ld hl,$80e0
	cp 1
	jr z,setlbl1
	res 1,(HL)
	ld ($80E1),a
	CALL_(DispHL)
	jr reslbl1
setlbl1:
	set 1,(HL)
	ld ($80E1),a
	CALL_(DispHL)
reslbl1:	
	CALL_(BitLoop)
	ld hl,$80E0
	cp 1
	jr z,setlbl0
	res 0,(HL)
	ld ($80E1),a
	CALL_(DispHL)
	jr reslbl0
setlbl0:
	set 0,(HL)
	ld ($80E1),a
	CALL_(DispHL)
reslbl0:
	ld a,($80df)
	ld c,a
	ld a,($80e0)
	out (c),a
	ret


KeyLoop:
	call GET_KEY
	or a
	jr z,KeyLoop
	cp K_1
	jr z,One
	cp K_2
	jr z,Two
	cp K_3
	jr z,Thr
	cp K_4
	jr z,For
	cp K_5
	jr z,Fiv
	cp K_6
	jr z,Six
	cp K_7
	jr z,Sev
	jr KeyLoop
One:
	ld a,1
	ret
Two:
	ld a,2
	ret
Thr:
	ld a,3
	ret
For:
	ld a,4
	ret
Fiv:
	ld a,5
	ret
Six:
	ld a,6
	ret
Sev:
	ld a,7
	ret

BitLoop:
	call GET_KEY
	or a
	jr z,BitLoop
	cp $21
	jr z,Zero
	cp $22
	jr OOne
	jr BitLoop
Zero:
	ld a,0
	ret
OOne:
	ld a,1
	ret

DispHL:
	ld hl,(PROGRAM_ADDR)
	ld de,Blanker
	add hl,de
	ld a,1
	ld (CURSOR_COL),a
	ld (CURSOR_ROW),a
	ROM_CALL(D_ZT_STR)
	ld a,1
	ld (CURSOR_COL),a
	ld (CURSOR_ROW),a
	ld a,0
	ld ($80E2),a
	ld hl,($80E1)
	ROM_CALL(D_HL_DECI)
	ret

Hello:
	.db "Enter Port:",0
Hello2:
	.db "Enter BITS:",0
Blanker:
	.db "           ",0

.end
