;***************************************************************************************** ; Mega 128 Scope Controller Program ; (c) Martin Cibulski ;***************************************************************************************** obj_init: rjmp obj_calc_dir_pointers ;***************************************************************************************** obj_test: ldi r16 ,low(2158) ldi r17 ,high(2158) ldi r18 ,4 ldi xl ,low(obj_ds_name) ldi xh ,high(obj_ds_name) call itoa rcall obj_calc_dir_pointers ldi r16 ,1 rcall obj_db_open ldi r16 ,low(2158-1) ldi r17 ,high(2158-1) rcall obj_db_read_dataset ldi r16 ,0 call obj_db_open ldi r16 ,59 ldi r17 ,0 call obj_db_read_dataset ldi xl ,low(obj_ds_name) ldi xh ,high(obj_ds_name) call lcd_print_x2 ret ;***************************************************************************************** ;Directory of Databases ;No of directory slots .EQU OBJ_DIR_SLOTS = 8 ;DB Storage types .EQU OBJ_DB_EMPTY = 0 .EQU OBJ_DB_FLASH = 1 .EQU OBJ_DB_RAM = 2 .EQU OBJ_DB_EEPROM = 4 .EQU OBJ_DB_XEEPROM = 8 ;DB Field Types .EQU OBJ_FLD_NONE = 0 .EQU OBJ_FLD_NAME = 1 .EQU OBJ_FLD_INT_RA = 2 .EQU OBJ_FLD_INT_DEC = 3 .EQU OBJ_FLD_LONG_RA = 4 .EQU OBJ_FLD_LONG_DEC = 5 .EQU OBJ_DB_OFF_DSETS = 2+2+24 ;**************************************************************************************** .EQU OBJ_DIR_OFF_NAME = 1 .EQU OBJ_DIR_OFF_SNAME = 9 .EQU OBJ_DIR_OFF_ADDR = 13 .EQU OBJ_DIR_ENTRYSIZE = 15 .ESEG obj_directory: .db OBJ_DB_FLASH ,"Stars "," " .dw obj_db_stars280 .db OBJ_DB_FLASH ,"Messier ","M " .dw obj_db_messier .db OBJ_DB_FLASH ,"NGC ","NGC " .dw obj_db_ngc .db OBJ_DB_FLASH ,"IC ","IC " .dw obj_db_ic .db OBJ_DB_FLASH ,"Abell PN","APN " .dw obj_db_abell_pn .db OBJ_DB_FLASH ,"Barnard ","Bar " .dw obj_db_barnard_dn .db OBJ_DB_FLASH ,"Abell GC","AGC " .dw obj_db_abell_gc .db OBJ_DB_EMPTY ," "," " .dw 0 ;**************************************************************************************** .DSEG obj_used_slots: .byte 1 obj_slt_low: .byte OBJ_DIR_SLOTS obj_slt_high: .byte OBJ_DIR_SLOTS obj_db_number: .byte 1 obj_db_name: .byte 8 obj_db_shortname: .byte 4 obj_db_start: .byte 3 obj_db_datasets: .byte 2 obj_db_fields: .byte 24+1 obj_db_ds_size: .byte 1 obj_ds_number: .byte 2 obj_ds_name: .byte 8 obj_ds_int_ra: .byte 2 obj_ds_int_dec: .byte 2 ;**************************************************************************************** .CSEG obj_calc_dir_pointers: push r17 ;slot counter push r18 ;used slot counter push yl ;directory entry ptr push yh push zl push zh ldi zl ,low(obj_directory) ;read type of directory entry ldi zh ,high(obj_directory) ldi yl ,low(obj_slt_low) ldi yh ,high(obj_slt_low) clr r17 clr r18 obj_cdp_loop: call eep_read cpi r16 ,OBJ_DB_EMPTY ;slot empty ? breq obj_cdp_01 ;yes, next slot st Y ,zl ;set ptr to used dir entry std Y+OBJ_DIR_SLOTS ,zh adiw yh:yl ,1 inc r18 obj_cdp_01: adiw zh:zl ,OBJ_DIR_ENTRYSIZE inc r17 ;next slot cpi r17 ,OBJ_DIR_SLOTS ;all slots tested ? brne obj_cdp_loop ;no sts obj_used_slots ,r18 ;save no of used slots pop zh pop zl pop yh pop yl pop r18 pop r17 ret ;**************************************************************************************** ;get file name from directory ; ;r16 entry number (in used slot list) ;xh:xl RAM buffer for name (8 bytes) obj_dir_get_longname: push r16 push r17 push yl push yh push zl push zh ldi yl ,low(obj_slt_low) ldi yh ,high(obj_slt_low) add yl ,r16 clr r16 adc yh ,r16 ld zl ,Y ldd zh ,Y+OBJ_DIR_SLOTS adiw zh:zl ,OBJ_DIR_OFF_NAME ldi r17 ,8 obj_dgln_loop: call eep_read adiw zh:zl ,1 st X+ ,r16 dec r17 brne obj_dgln_loop sbiw xh:xl ,8 pop zh pop zl pop yh pop yl pop r17 pop r16 ret ;**************************************************************************************** ;get file name from directory ; ;r16 entry number (in used slot list) ;xh:xl RAM buffer for name (8 bytes) obj_dir_get_shortname: push r16 push r17 push yl push yh push zl push zh ldi yl ,low(obj_slt_low) ldi yh ,high(obj_slt_low) add yl ,r16 clr r16 adc yh ,r16 ld zl ,Y ldd zh ,Y+OBJ_DIR_SLOTS adiw zh:zl ,OBJ_DIR_OFF_SNAME ldi r17 ,4 obj_dgsn_loop: call eep_read adiw zh:zl ,1 st X+ ,r16 dec r17 brne obj_dgsn_loop sbiw xh:xl ,4 pop zh pop zl pop yh pop yl pop r17 pop r16 ret ;**************************************************************************************** ;open database ;r16 database number (in used slot list) obj_db_open: push r17 push r24 push r25 push yl push yh push zl push zh sts obj_db_number ,r16 ldi xl ,low(obj_db_name) ldi xh ,high(obj_db_name) rcall obj_dir_get_longname ldi xl ,low(obj_db_shortname) ldi xh ,high(obj_db_shortname) rcall obj_dir_get_shortname ldi yl ,low(obj_slt_low) ldi yh ,high(obj_slt_low) add yl ,r16 clr r16 adc yh ,r16 ld zl ,Y ;ptr to directory entry ldd zh ,Y+OBJ_DIR_SLOTS adiw zh:zl ,OBJ_DIR_OFF_ADDR ;ptr to file start adress clr r1 call eep_read ;file start adress mov r0 ,r16 adiw zh:zl ,1 call eep_read lsl r0 rol r16 rol r1 sts obj_db_start ,r0 sts obj_db_start+1 ,r16 sts obj_db_start+2 ,r1 ldi r24 ,0 ldi r25 ,0 rcall obj_db_read sts obj_db_datasets ,r16 rcall obj_db_read sts obj_db_datasets+1 ,r16 rcall obj_db_read sts obj_db_ds_size ,r16 rcall obj_db_read sts obj_db_ds_size+1 ,r16 ldi r17 ,12 ;read field list ldi xl ,low(obj_db_fields) ldi xh ,high(obj_db_fields) obj_dbo_01: rcall obj_db_read ;field type st X+ ,r16 rcall obj_db_read ;field size (bits) st X+ ,r16 dec r17 brne obj_dbo_01 ldi r16 ,OBJ_FLD_NONE st X ,r16 pop zh pop zl pop yh pop yl pop r25 pop r24 pop r17 ret ;**************************************************************************************** ;read dataset from memory file into field variables ; ;r17:r16 dataset no ;**************************************************************************************** obj_db_read_dataset: push r18 push r24 push r25 push xl push xh push yl push yh push zl push zh sts obj_ds_number ,r16 ;16 bit number sts obj_ds_number+1 ,r17 ldi yl ,low(obj_db_shortname) ;copy db short name as first part ldi yh ,high(obj_db_shortname) ;of default object name ldi xl ,low(obj_ds_name) ldi xh ,high(obj_ds_name+1) ldi r24 ,' ' ldi r25 ,0 clr r0 dec r0 obj_rds_00: ld r1 ,Y+ st X+ ,r1 cpse r1 ,r24 mov r0 ,r25 ;save position of last non space inc r25 ;copy next char cpi r25 ,4 brne obj_rds_00 obj_rds_04: st X+ ,r24 dec r25 ;fill with 4 more spaces brne obj_rds_04 obj_rds_02: mov r25 ,r0 ;position of last non space inc r25 ;start at next position breq obj_ds_05 ;= pos 0 if no database short name cpi r25 ,4 ;= pos 4 if len(databse short name) = 4 breq obj_ds_05 inc r25 ;add one space between name and number obj_ds_05: ldi xl ,low(obj_ds_name) ;write dataset number behind ldi xh ,high(obj_ds_name+1) ;database short name add xl ,r25 ;calc string pointer clr r25 adc xh ,r25 ldi r18 ,4 sec ;dataset number + 1 adc r16 ,r25 adc r17 ,r25 call itoa ;convert to decimal digits lds r16 ,obj_ds_number ;16 bit number lds r17 ,obj_ds_number+1 ldi r24 ,low(OBJ_DB_OFF_DSETS) ;calculate file pointer ldi r25 ,high(OBJ_DB_OFF_DSETS) ;r25:r24 lds r18 ,obj_db_ds_size mul r16 ,r18 add r24 ,r0 adc r25 ,r1 mul r17 ,r18 add r25 ,r0 ldi yl ,low(obj_db_fields) ;field types and sizes ldi yh ,high(obj_db_fields) obj_rds_loop: ld r16 ,Y+ ;field type ld r17 ,Y+ ;field size (bits) cpi r16 ,OBJ_FLD_NONE ;end of field list ? brne obj_rds_check_name ;no, check field type pop zh ;yes, return pop zl pop yh pop yl pop xh pop xl pop r25 pop r24 pop r18 ret obj_rds_check_name: cpi r16 ,OBJ_FLD_NAME ;NAME field ? brne obj_rds_check_int_ra ;no ldi xl ,low(obj_ds_name) ;read 64 bits NAME ldi xh ,high(obj_ds_name+1) obj_rds_01: rcall obj_db_read st X+ ,r16 subi r17 ,8 brne obj_rds_01 rjmp obj_rds_loop obj_rds_check_int_ra: cpi r16 ,OBJ_FLD_INT_RA ;RA field ? brne obj_rds_check_int_dec ;no rcall obj_db_read sts obj_ds_int_ra+1 ,r16 rcall obj_db_read sts obj_ds_int_ra ,r16 rjmp obj_rds_loop obj_rds_check_int_dec: cpi r16 ,OBJ_FLD_INT_DEC ;DEC field ? brne obj_rds_check_end ;no rcall obj_db_read sts obj_ds_int_dec+1 ,r16 rcall obj_db_read sts obj_ds_int_dec ,r16 rjmp obj_rds_loop obj_rds_check_end: ;UNKNOWN field ? ;read bits rjmp obj_rds_loop ;**************************************************************************************** ;read byte from memory file ; ;r25:r24 byte offset into file ;**************************************************************************************** obj_db_read: push zl push zh clr r0 lds zl ,obj_db_start ;24 bit file start adress lds zh ,obj_db_start+1 lds r1 ,obj_db_start+2 add zl ,r24 ;add byte offset adc zh ,r25 adc r1 ,r0 out rampz ,r1 elpm r16 ,Z adiw r25:r24 ,1 pop zh pop zl ret ;**************************************************************************************** obj_db_stars280: .dw 280 ;no of datasets .dw 12 ;dataset size .db OBJ_FLD_NAME ,64 ;dataset fields list .db OBJ_FLD_INT_RA ,16 ;type , bits .db OBJ_FLD_INT_DEC ,16 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .include "Stars280.txt" ;**************************************************************************************** obj_db_messier: .dw 110 ;no of datasets .dw 4 ;dataset size .db OBJ_FLD_INT_RA ,16 ;dataset fields list .db OBJ_FLD_INT_DEC ,16 ;type , bits .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .include "Messier.txt" ;**************************************************************************************** obj_db_ngc: .dw 7840 ;no of datasets .dw 4 ;dataset size .db OBJ_FLD_INT_RA ,16 ;dataset fields list .db OBJ_FLD_INT_DEC ,16 ;type , bits .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .ifndef EXCLUDE_DB .include "NGC.txt" .endif ;**************************************************************************************** obj_db_ic: .dw 5386 ;no of datasets .dw 4 ;dataset size .db OBJ_FLD_INT_RA ,16 ;dataset fields list .db OBJ_FLD_INT_DEC ,16 ;type , bits .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .ifndef EXCLUDE_DB .include "IC.txt" .endif ;**************************************************************************************** obj_db_abell_pn: .dw 17 ;no of datasets .dw 12 ;dataset size .db OBJ_FLD_NAME ,64 ;dataset fields list .db OBJ_FLD_INT_RA ,16 ;type , bits .db OBJ_FLD_INT_DEC ,16 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .include "Abell_PN.txt" ;**************************************************************************************** obj_db_barnard_dn: .dw 71 ;no of datasets .dw 12 ;dataset size .db OBJ_FLD_NAME ,64 ;dataset fields list .db OBJ_FLD_INT_RA ,16 ;type , bits .db OBJ_FLD_INT_DEC ,16 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .include "Barnard_DN.txt" ;**************************************************************************************** obj_db_abell_gc: .dw 32 ;no of datasets .dw 12 ;dataset size .db OBJ_FLD_NAME ,64 ;dataset fields list .db OBJ_FLD_INT_RA ,16 ;type , bits .db OBJ_FLD_INT_DEC ,16 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .db OBJ_FLD_NONE , 0 .include "Abell_GC.txt" ;*****************************************************************************************