home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 86 / asm / source / on86.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  13.0 KB  |  377 lines

  1. ;On86 3.1
  2. ;by Jonah Cohen <ComAsYuAre@aol.com>
  3. ;http://jonah.ticalc.org
  4.  
  5.  
  6. #include "TI86.inc"
  7.  
  8. password_size       equ     $d610
  9. password            equ     $d611
  10. temp_size           equ     $8800
  11. temp_pw             equ     $8801
  12. temp_size2          equ     $8900
  13. temp_pw2            equ     $8901
  14.  
  15.  
  16. .org _asm_exec_ram
  17.  
  18.  
  19. #define checksum $2a
  20.  
  21. #ifndef checksum
  22.     call _clrWindow         ;clear screen
  23.     ld a,'$'                ;since it's a hex digit
  24.     call _putc              ;display char
  25. ;calculate the checksum
  26.     ld hl,off               ;start of off routine
  27.     ld de,_alt_off_exec     ;where it goes in ram
  28.     push de                 ;save this pointer
  29.     ld bc,off_end-off       ;size to copy
  30.     ldir                    ;copy it
  31.     pop hl                  ;retrieve pointer to _alt_off_exec
  32.     ld a,(hl)               ;get first byte
  33.     dec hl                  ;since checksum is 1st, 40th, 80th, etc, we subtract 1
  34.     ld de,40                ;increment between bytes
  35.     ld b,5                  ;number of bytes we're adding
  36. checksum_loop:
  37.     add hl,de               ;go to next byte
  38.     add a,(hl)              ;add byte to checksum
  39.     djnz checksum_loop      ;loop 5 times
  40.     ld (_alt_off_chksum),a  ;store in memory
  41. ;a contains checksum.  now we display it
  42.     push af                 ;save checksum
  43.     call _SHRACC            ;a=upper nibble
  44.     call dispnibble         ;display it
  45.     pop af                  ;retrieve checksum
  46.     and $0f                 ;mask off upper nibble
  47.     call dispnibble         ;display lower nibble
  48.     jp _newline             ;go to next line and quit
  49.  
  50. dispnibble:
  51.     cp 10
  52.     jr nc,skipadd           ;check if A-F
  53.     add a,'0'               ;if not, add '0'
  54. skipadd:
  55.     jp _putc                ;display digit
  56. #endif
  57.  
  58.  
  59.     nop
  60.     jp start
  61.     .dw 0
  62.     .dw comment
  63.  
  64.  
  65. off_checksum:
  66. #ifdef checksum
  67.     .db checksum
  68. #endif
  69. off:
  70.     ei                      ;enable interrupts
  71.     ld (_onCheckSum),a      ;in case they pull a battery
  72. release_key:
  73.     halt
  74.     in a,(3)
  75.     bit 3,a
  76.     jr z,release_key        ;make sure they aren't holding down on
  77.  
  78. shutdown:
  79.     ld hl,(_curRow)         ;get cursor row/col
  80.     push hl                 ;save onto stack
  81.     ld a,1
  82.     out (3),a               ;turn off screen
  83.     halt                    ;wait for on key
  84.     res 1,(iy+13)           ;don't save to textShadow
  85.     call _cursorOff         ;turn off cursor
  86.  
  87.     ld a,11
  88.     out (3),a               ;turn on screen
  89.  
  90.     call get_password-off+_alt_off_exec
  91.                             ;get password
  92.  
  93.     pop de                  ;retrieve cursor position
  94.     ld (_curRow),de         ;restore cursor
  95.  
  96.     ld ix,_JforceCmdNoChar  ;return to home screen if correct password
  97.  
  98.     ld bc,shutdown-off+_alt_off_exec    ;shutdown if incorrect password
  99.     push bc                 ;so it can return to it
  100.  
  101. check_password:
  102.     ld de,password_size     ;de points to real password
  103. check_pw:
  104.     call _pstrCmp           ;compare passwords
  105.     ret nz                  ;return if not equal
  106. ;data equal
  107.     pop af                  ;clean up stack
  108.     jp (ix)                 ;passwords equal
  109.  
  110. title = $-off+_alt_off_exec
  111.     call _clrLCD            ;clear screen
  112.     ld hl,$002b             ;move pen location
  113. column = $-2-off+_alt_off_exec
  114.     ld (_penCol),hl
  115.     ld hl,message-off+_alt_off_exec
  116.                             ;display title message
  117.     call _vputs             ;display message
  118.     ld de,$fc70             ;hl points to video mem
  119. reverseline:
  120.     dec e                   ;move to next byte
  121.     ld a,(de)               ;get byte
  122.     cpl                     ;reverse it
  123.     ld (de),a               ;store it
  124.     jr nz,reverseline       ;repeat until we're at top
  125.     ret
  126.  
  127. get_password:
  128.     ld hl,enter_password-off+_alt_off_exec
  129.                             ;display "Enter password:"
  130. get_pw:
  131.     push hl
  132.     call title              ;clear screen
  133.     pop hl
  134.     ld c,2                  ;third line
  135.     ld (_curRow),bc
  136.     ld de,temp_size         ;store here
  137. get_pw_skip:
  138.     call _puts              ;display message
  139.     ld hl,password_end-off+_alt_off_exec
  140.     call _puts              ;finish prompt with " password:"
  141.     call _newline           ;next line
  142.     ld h,d                  ;hl->password length
  143.     ld l,e
  144.     ld (hl),l               ;reset length
  145.     ld b,15                 ;set counter for 15 keypresses max
  146. pw_loop:
  147.     inc (hl)                ;increment password length
  148.     inc de                  ;move de to next byte in storage
  149.     push hl                 ;save length pointer
  150. key_input:
  151.     call _getcsc            ;get a key
  152.     or a                    ;is it 0?
  153.     jr z,key_input          ;if so, get another keypress
  154.     pop hl                  ;retrieve length pointer
  155.     ld (de),a               ;store input at temporary password storage
  156.     cp K_ENTER              ;is it enter?
  157.     ret z                   ;if so, return.
  158.     ld a,'*'                ;print a * to the screen
  159.     call _putc
  160.     djnz pw_loop            ;get next keypress
  161.     ret
  162.  
  163.  
  164. ;messages used in off routine
  165.  
  166. enter_password:             .db "Enter",0
  167. password_end:               .db " Password:",0
  168. message:                    .db "Property of "
  169. name = $-off+_alt_off_exec
  170.  
  171. off_end:                    ;end of off routine
  172.  
  173.  
  174. display:                    ;pause with message displayed
  175.     push hl
  176.     call title              ;clear screen, keeping title bar at top
  177.     pop hl
  178.     ld c,(hl)               ;retrieve column
  179.     inc hl
  180.     ld b,$1c                ;normal row location
  181.     call vputs              ;display message
  182. getkey:
  183.     call _getcsc            ;get keypress
  184.     or a                    ;did they hit anything?
  185.     jr z,getkey             ;if not, keep looping
  186.     ret
  187.  
  188. move_loop:
  189. ;bc is current penCol and penRow
  190. ;moves pen cursor down 9 pixels and displays whatever hl points to.
  191.     ld a,b
  192.     add a,9
  193.     ld b,a
  194. vputs:
  195.     ld (_penCol),bc         ;move cursor
  196.  
  197. cvputs:
  198. ;display message
  199.     ld a,(hl)               ;get character
  200.     inc hl                  ;increment string pointer
  201.     add a,a                 ;check for a=0 or bit 7 set
  202.     ret z                   ;return if 0
  203.     push af                 ;save character
  204.     call c,_VPUTBLANK       ;if bit 7 set, display preceding space
  205.     pop af                  ;retrieve character
  206.     rrca                    ;shift right again
  207.     call _vputmap           ;display character
  208.     jr cvputs               ;loop until we hit 0
  209.  
  210. start:
  211.     call _runIndicOff       ;turn off run indicator
  212.     call _flushAllMenus     ;close all menus
  213.  
  214.     ld a,(column)           ;save column before recopying
  215.  
  216.     ld l,off_checksum&$ff   ;h=$d7 from _flushAllMenus
  217.     ld de,_alt_off_chksum   ;start of off routine
  218.     ld c,name-_alt_off_chksum ;safe size to copy
  219.     ldir                    ;restore beginning of _alt_off
  220.  
  221.     ld c,a                  ;save column in b
  222.     ld hl,password_size     ;point to password length
  223.     ld a,(hl)               ;get length
  224.     or a                    ;if 0, not installed yet
  225.     jr nz,not_new           ;valid password already there
  226. d
  227.     ld (de),a               ;reset name
  228.  
  229.     inc (hl)                ;1 is default password length
  230.     inc hl
  231.     ld (hl),K_ENTER         ;enter is default password
  232.     jr menu                 ;skip password prompt
  233.  
  234. not_new:
  235.     ld a,c                  ;get column in a
  236.     ld (column),a           ;restore column
  237.     call get_password       ;get password from user
  238.     ld ix,menu              ;go here if correct
  239.     call check_password     ;check passwords
  240. ;wrong password
  241.     ld hl,wrong_pw_message  ;hl points to message "incorrect password."
  242.     call display            ;pause with message
  243.  
  244. exit:
  245.     res 4,(iy+9)            ;no error 07 break if they hit on
  246.     jp _clrWindow           ;clear screen, move cursor to upper left, then quit
  247.  
  248. menu:
  249.     call title              ;display title
  250.     ld bc,$0e0b             ;move pen location
  251.     ld hl,f1                ;display first message
  252.     call vputs
  253.     call move_loop          ;display second message
  254.     bit 7,(iy+$23)          ;if alternate off routine flag isn't set, F3 enables it
  255.     jr z,not_disable        ;otherwise, F3 disables it
  256.     ld l,disable&$ff        ;change message
  257. not_disable:
  258.     call move_loop          ;move cursor and display text
  259.     ld l,able_message&$ff   ;last part of message ("able On86")
  260.     call cvputs
  261.     call move_loop          ;display exit
  262.  
  263. start_loop:
  264.     call _getcsc            ;get a keypress
  265.     cp K_EXIT               ;is it exit?
  266.     jr z,exit               ;if so, exit
  267.     sub K_F1                ;is it F1?
  268.     jr z,new_password       ;get new password
  269.     inc a                   ;is it F2?
  270.     jr z,new_name           ;get new name
  271.     inc a                   ;is it F3?
  272.     jr nz,start_loop        ;if not, get another keypress
  273.  
  274. change_flag:
  275.     ld hl,_Flags+$23        ;alt routine flag
  276.     ld a,(hl)               ;get byte
  277.     xor $80                 ;toggle on/off
  278.     ld (hl),a               ;store toggled flag
  279.     jr menu                 ;back to main menu
  280.  
  281. store_pw:
  282.                             ;hl points to new password
  283.     ld de,password_size     ;de points to old password where we're copying to
  284.     ld c,16                 ;1 byte for size, 15 for password (b=0 already)
  285.     ldir                    ;save password
  286.     jr menu                 ;back to main menu
  287.  
  288. new_password:
  289.     ld hl,new               ;"Enter new password:"
  290.     call get_pw             ;get password
  291.     push hl                 ;save pointer to first password
  292.  
  293.     call _newline           ;move to next line
  294.     ld hl,verify            ;message: "Verify password:"
  295.     ld de,temp_size2
  296.     call get_pw_skip        ;get second input
  297.     pop de                  ;retrieve first password pointer
  298.     ld ix,store_pw          ;where to go if passwords are identical
  299.     call check_pw           ;check passwords
  300. ;a mistype
  301.     ld hl,mistype_message   ;hl points to message "passwords do not match."
  302.     call display            ;display and pause
  303. menu_:
  304.     jr menu                 ;back to main menu
  305.  
  306.  
  307. new_name:
  308.     ld bc,$320b             ;below "Exit"
  309.     ld hl,enter_name        ;"Enter name: "
  310.     call vputs              ;display prompt
  311.     ld hl,name              ;hl points to name
  312.     ld (hl),a               ;reset name
  313.     ld d,'A'                ;first letter uppercase
  314. get_name:
  315.     push hl                 ;save name pointer
  316.     call _getcsc            ;get key
  317.     ld hl,letters           ;point to key table
  318.     ld bc,26                ;26 letters
  319.     cpir                    ;search for key
  320.     pop hl                  ;retrieve name
  321.     jr nz,check_space       ;not a letter
  322.     ld a,c                  ;get letter
  323.     add a,d                 ;add to "case"
  324.     ld d,'a'                ;next letter lowercase
  325.     jr add_letter           ;insert letter
  326. check_space:
  327.     cp K_SIGN               ;check for space
  328.     jr nz,check_enter
  329.     ld a,' '                ;character
  330.     ld d,'A'                ;next letter uppercase
  331. add_letter:
  332.     ld c,a
  333.     ld a,l                  ;get string pointer
  334.     cp (password_size-2)&$ff;check if we're at end
  335.     jr z,get_name           ;can't add any letters
  336.     ld (hl),c               ;store letter
  337.     inc hl                  ;increment pointer
  338.     ld (hl),b               ;null terminator
  339.     ld a,c                  ;get char back
  340.     push de
  341.     call _vputmap           ;display letter
  342.     pop de
  343.     jr get_name             ;get another letter
  344. check_enter:
  345.     cp K_EXIT               ;check for exit
  346.     jr z,got_name           ;if so, save name
  347.     cp K_ENTER              ;check for enter
  348.     jr nz,get_name          ;if not, get another letter
  349. got_name:
  350.     ld a,(_penCol)          ;get column
  351.     rra                     ;divide by two
  352.     cpl                     ;make negative
  353.     add a,70                ;center it
  354.     ld (column),a           ;store as column for on prompt
  355.     jr menu_                ;redraw menu
  356.  
  357.  
  358. ;messages not used in off routine
  359.  
  360. new:                        .db "Enter new",0
  361. verify:                     .db "Verify",0
  362. enter_name:                 .db "Enter",$80+'n',"ame: ",0
  363. f1:                         .db "F1",$80+'-',$80+'C',"hange",$80+'P',"assword",0
  364.                             .db "F2",$80+'-',$80+'C',"hange",$80+'N',"ame",0
  365. enable:                     .db "F3",$80+'-'," En",0
  366. disable:                    .db "F3",$80+'-'," Dis",0
  367. able_message:               .db "able",$80+'O',"n86",0
  368.                             .db "Exit",$80+'-',$80+'Q',"uit",$80+'O',"n86",0
  369. wrong_pw_message:           .db $1e,"Incorrect",$80+'P',"assword",0
  370. mistype_message:            .db $18,"Passwords",$80+'d','o',$80+'n',"ot",$80+'m',"atch",0
  371. comment:                    .db "On86 3.1 by Jonah Cohen",0
  372.  
  373. letters:                    .db $19,$21,$0a,$12,$1a,$22,$0b,$13,$1b
  374.                             .db $23,$2b,$0c,$14,$1c,$24,$2c,$0d,$15
  375.                             .db $1d,$25,$2d,$0e,$16,$1e,$26,$2e
  376.  
  377. .end
  378.