Mercurial > repos > blastem
comparison cdd_mcu.c @ 2280:9ead0fe69d9b
Implement savestate support for Sega CD
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 08 Jan 2023 14:42:24 -0800 |
parents | 827ab6dd534a |
children | 047253715fd8 |
comparison
equal
deleted
inserted
replaced
2279:3b5fef896475 | 2280:9ead0fe69d9b |
---|---|
807 context->next_byte_cycle -= cd_deduction; | 807 context->next_byte_cycle -= cd_deduction; |
808 if (context->next_subcode_cycle != CYCLE_NEVER) { | 808 if (context->next_subcode_cycle != CYCLE_NEVER) { |
809 context->next_subcode_cycle -= cd_deduction; | 809 context->next_subcode_cycle -= cd_deduction; |
810 } | 810 } |
811 } | 811 } |
812 | |
813 void cdd_mcu_serialize(cdd_mcu *context, serialize_buffer *buf) | |
814 { | |
815 save_int32(buf, context->cycle); | |
816 save_int32(buf, context->next_int_cycle); | |
817 save_int32(buf, context->next_subcode_int_cycle); | |
818 save_int32(buf, context->last_sector_cycle); | |
819 save_int32(buf, context->last_nibble_cycle); | |
820 save_int32(buf, context->next_byte_cycle); | |
821 save_int32(buf, context->next_subcode_cycle); | |
822 save_int8(buf, context->current_status_nibble); | |
823 save_int8(buf, context->current_cmd_nibble); | |
824 save_int16(buf, context->current_sector_byte); | |
825 save_int8(buf, context->current_subcode_byte); | |
826 save_int8(buf, context->current_subcode_dest); | |
827 save_int32(buf, context->head_pba); | |
828 save_int32(buf, context->seek_pba); | |
829 save_int32(buf, context->pause_pba); | |
830 save_int32(buf, context->coarse_seek); | |
831 save_buffer8(buf, (uint8_t *)&context->cmd_buffer, sizeof(context->cmd_buffer)); | |
832 save_buffer8(buf, (uint8_t *)&context->status_buffer, sizeof(context->status_buffer)); | |
833 save_int8(buf, context->requested_format); | |
834 save_int8(buf, context->status); | |
835 save_int8(buf, context->error_status); | |
836 save_int8(buf, context->requested_track); | |
837 save_int8(buf, context->cmd_recv_wait); | |
838 save_int8(buf, context->cmd_recv_pending); | |
839 save_int8(buf, context->int_pending); | |
840 save_int8(buf, context->subcode_int_pending); | |
841 save_int8(buf, context->toc_valid); | |
842 save_int8(buf, context->first_cmd_received); | |
843 save_int8(buf, context->seeking); | |
844 save_int8(buf, context->in_fake_pregap); | |
845 } | |
846 | |
847 static int sign_extend8(uint8_t value) | |
848 { | |
849 if (value & 0x80) { | |
850 return value | 0xFFFFFF00; | |
851 } else { | |
852 return value; | |
853 } | |
854 } | |
855 | |
856 static int sign_extend16(uint16_t value) | |
857 { | |
858 if (value & 0x8000) { | |
859 return value | 0xFFFF0000; | |
860 } else { | |
861 return value; | |
862 } | |
863 } | |
864 | |
865 void cdd_mcu_deserialize(deserialize_buffer *buf, void *vcontext) | |
866 { | |
867 cdd_mcu *context = vcontext; | |
868 context->cycle = load_int32(buf); | |
869 context->next_int_cycle = load_int32(buf); | |
870 context->next_subcode_int_cycle = load_int32(buf); | |
871 context->last_sector_cycle = load_int32(buf); | |
872 context->last_nibble_cycle = load_int32(buf); | |
873 context->next_byte_cycle = load_int32(buf); | |
874 context->next_subcode_cycle = load_int32(buf); | |
875 context->current_status_nibble = sign_extend8(load_int8(buf)); | |
876 context->current_cmd_nibble = sign_extend8(load_int8(buf)); | |
877 context->current_sector_byte = sign_extend16(load_int16(buf)); | |
878 context->current_subcode_byte = sign_extend8(load_int8(buf)); | |
879 context->current_subcode_dest = sign_extend8(load_int8(buf)); | |
880 context->head_pba = load_int32(buf); | |
881 context->seek_pba = load_int32(buf); | |
882 context->pause_pba = load_int32(buf); | |
883 context->coarse_seek = load_int32(buf); | |
884 load_buffer8(buf, (uint8_t *)&context->cmd_buffer, sizeof(context->cmd_buffer)); | |
885 load_buffer8(buf, (uint8_t *)&context->status_buffer, sizeof(context->status_buffer)); | |
886 context->requested_format = load_int8(buf); | |
887 context->status = load_int8(buf); | |
888 context->error_status = load_int8(buf); | |
889 context->requested_track = load_int8(buf); | |
890 context->cmd_recv_wait = load_int8(buf); | |
891 context->cmd_recv_pending = load_int8(buf); | |
892 context->int_pending = load_int8(buf); | |
893 context->subcode_int_pending = load_int8(buf); | |
894 context->toc_valid = load_int8(buf); | |
895 context->first_cmd_received = load_int8(buf); | |
896 context->seeking = load_int8(buf); | |
897 context->in_fake_pregap = load_int8(buf); | |
898 } |